Данный отчёт сгенерирован 04.04.2023 06:21:13 UTC.
HTML версия (этот сайт) сгенерирован 04.04.2023 06:21:31 UTC.
Коммит: [bfeb65b9] add automatic zip creation
04.04.2023 06:21:13
Задача: Анаграми 04.04.2023 06:21:13
Описание: Слово називається анаграмою іншого слова, якщо є перестановкою букв іншого слова. Оголосити метод Anagram(w1, w2), який отримує два слова та повертає true, якщо слова є анаграмами один одного. В іншому випадку метод повертає false. Не використовувати метод Sort. 04.04.2023 06:21:13
Решений: 42 04.04.2023 06:21:13
Анаграми 04.04.2023 06:21:13
 static bool Anagram(string w1, string w2)
{
    string c1 = String.Concat(w1.ToLower().OrderBy(c => c));
    string c2 = String.Concat(w2.ToLower().OrderBy(c => c));
    return c1 == c2;
}
 static bool Anagram(string w1, string w2){
    if (w1.Length != w2.Length) {
            return false;
        }
        
        int[] charCount = new int[256];
        
        foreach (char c in w1) {
            charCount[(int)c]++;
        }
        
        foreach (char c in w2) {
            charCount[(int)c]--;
            
            if (charCount[(int)c] < 0) {
                return false;
            }
        }
        
        return true;
}
 static bool Anagram(string w1, string w2){
    if (w1.Length != w2.Length) {
            return false;
        }
        
        int[] charCount = new int[256];
        
        foreach (char c in w1) {
            charCount[(int)c]++;
        }
        
        foreach (char c in w2) {
            charCount[(int)c]--;
            
            if (charCount[(int)c] < 0) {
                return false;
            }
        }
        
        return true;
}
 static bool Anagram(string w1, string w2)
{
    return (w1 + w2).ToLower().Aggregate(0, (a, n) => a ^ n) == 0;
}
 static bool Anagram(string w1, string w2)
    {
        if (w1.Length == w2.Length)
        {
            int count = 0;
            string[] arr = new string[w2.Length];
            string[] arr2 = new string[w2.Length];
            for (int i = 0; i < w2.Length; i++)
            {
                arr[i] = Convert.ToString(w1[i]);
                arr2[i] = Convert.ToString(w2[i]);
            }
            for (int i = 0; i < w2.Length; i++)
            {
                for (int j = 0; j < w2.Length; j++)
                {
                    if (arr[i] == arr2[j])
                    {
                        count++;
                        arr[i] = null;
                        arr2[j] = null;
                        break;
                    }
                }
            }
            return count == w1.Length ? true : false;
        }
        else return false;
    }
 static bool Anagram(string w1, string w2){
    if(w1.Length!=w2.Length){
        return false;
    }
    char[] s1 = w1.ToCharArray();
    char[] s2 = w2.ToCharArray();
    for(int i=0;i< s1.Length;i++){
        for(int j=0;j< s2.Length;j++){
            if(s1[i]==s2[j]){
                s1[i]='_';
                s2[j]='_';
            }
        }
    }
    w1= new string(s1);
    w2= new string(s2);
    return w1==w2;
}
 static bool Anagram(string w1, string w2){
    string w1_edited = String.Concat(w1.OrderBy(c=>c));
    string w2_edited = String.Concat(w2.OrderBy(c=>c));
    if (w2_edited == w1_edited){
        return true;
    }
    else{
        return false;
    }
}
 static bool Anagram(string w1, string w2)
{
    int count = 0;
    if (w1.Length == w2.Length)
    {
        char[] str1Array = w1.ToCharArray();
        char[] str2Array = w2.ToCharArray();
        for (int i = 0; i < w1.Length; i++)
        {
            for (int j = 0; j < str2Array.Length; j++)
            {
                if (str1Array[i] == str2Array[j])
                {
                    char[] newArray = new char [str2Array.Length - 1];
                    Array.Copy(str2Array, 0, newArray, 0, j);
                    Array.Copy(str2Array, j + 1, newArray, j, str2Array.Length - 1 - j);
                    str2Array = newArray;
                    count++;
                    break;
                }
            }
        }
    }
    return count == w1.Length;
}
 public static bool Anagram(string w1, string w2)
{
    if (w1.Length != w2.Length)
    {
        return false;
    }

    var dict1 = new System.Collections.Generic.Dictionary< char, int>();
    var dict2 = new System.Collections.Generic.Dictionary< char, int>();

    for (int i = 0; i < w1.Length; i++)
    {
        char c1 = w1[i];
        char c2 = w2[i];

        if (!dict1.ContainsKey(c1))
        {
            dict1[c1] = 0;
        }
        dict1[c1]++;

        if (!dict2.ContainsKey(c2))
        {
            dict2[c2] = 0;
        }
        dict2[c2]++;
    }

    foreach (var kvp in dict1)
    {
        char c = kvp.Key;
        int count1 = kvp.Value;
        int count2 = 0;
        if (!dict2.TryGetValue(c, out count2) || count1 != count2)
        {
            return false;
        }
    }

    return true;
}
 static bool Anagram(string w1, string w2){
    bool res = true;
    if(w1.Length == w2.Length){
    for(int i = 0;i < w1.Length;i++){
        for(int j = 0;j < w1.Length;j++){
            if(w1[i]== w2[j]){
                w1 = w1.Remove(i,1);
                w2 = w2.Remove(j,1);
                i -= 1;
                break;
            }
        }
    }
    }
    if(w1.Length > 0||w2.Length > 0){
        res = false;
    }
    return res;
}
 static bool Anagram(string w1, string w2)
        {
            bool res=true;
            if (w1.Length == w2.Length)
            {
                for (int i = 0; i < w1.Length; i++)
                {
                    int elm = w1[i];
                    int kilkElm1 = checkKilk(w1, elm);
                    int kilkElm2= checkKilk(w2, elm);
                    if(kilkElm1!= kilkElm2) { 
                        res = false;
                        break;
                    }
                }
            }
            else res=false; 
            
            static int checkKilk(string w, int elm)
            {
                int kilk = 0;
                for(int j=0; j < w.Length; j++)
                {
                    if (w[j]==elm) kilk++;
                }
                return kilk;
            }
            return res;
        }
 public static bool Anagram(string w1, string w2)
{
 
    if (w1.Length != w2.Length)
    {
        return false;
    }

    int[] letterCounts = new int[256];

    for (int i = 0; i < w1.Length; i++)
    {
        char c = w1[i];
        letterCounts[c]++;
    }
   
    for (int i = 0; i < w2.Length; i++)
    {
        char c = w2[i];
        letterCounts[c]--;

        if (letterCounts[c] < 0)
        {
            return false;
        }
    }

    for (int i = 0; i < letterCounts.Length; i++)
    {
        if (letterCounts[i] != 0)
        {
            return false;
        }
    }

    return true;
}
 static bool Anagram(string w1, string w2){
    string w1_edited = String.Concat(w1.OrderBy(c=>c));
    string w2_edited = String.Concat(w2.OrderBy(c=>c));
    if (w2_edited == w1_edited){
        return true;
    }
    else{
        return false;
    }
}
 static bool Anagram(string w1, string w2)
        {
            int count =0;
            T1 : for(int i = 0; i < w1.Length; i++)
            {
                for(int j = 0; j < w2.Length; j++)
                {
                    if(w1[i] == w2[j] )
                    {    
                        w1 = w1.Substring(0, i)+ w1.Substring(i+1);
                        w2 = w2.Substring(0, j)+ w2.Substring(j+1);
                        count++;
                        goto T1;
                    }
                }
            }
            return (w1 == w2);
        }
 static bool Anagram(string w1, string w2)
{
    if (w1.Length != w2.Length)
        return false;

    int[] letters = new int[256];

    for (int i = 0; i < w1.Length; i++)
    {
        letters[w1[i]]++;
        letters[w2[i]]--;
    }

    for (int i = 0; i < letters.Length; i++)
    {
        if (letters[i] != 0)
            return false;
    }

    return true;
}
 static bool Anagram(string w1, string w2)
{
    if (w1.Length != w2.Length) return false;

    char[] m1 = w1.ToCharArray();
    char[] m2 = w2.ToCharArray();

    int k = 0;
    for (int i = 0; i < m1.Length; i++)
    {
        for (int j = 0; j < m2.Length; j++)
        {
            if (m1[i] == m2[j])
            {
                k++;
                m2[j] = ' ';
                break;
            }
        }
    }
    return k == m1.Length;
}
 static bool Anagram(string w1, string w2) {
        if (w1.Length != w2.Length) return false;

        int [] charCount = new int[256];
        for (int i = 0; i < w1.Length; i++)
        {
            charCount[w1[i]]++;
            charCount[w2[i]]--;
        }

        for (int i = 0; i < charCount.Length; i++)
        {
            if (charCount[i] != 0) return false;
        }

        return true;
    }
 static bool Anagram(string w1, string w2)
{
    if(w1.Length!=w2.Length) return false;
    char[] arr = w2.ToCharArray();
     for(int i = 0;i< w1.Length;i++)
     {
         for(int q = 0;q< w2.Length;q++)
         {
             if(w1[i]==arr[q])
             {
                 arr[q] = '*';
                 break;
             }
             if(q==w2.Length-1) return false;
         }
     }
    return true;
}
 static bool Anagram(string w1, string w2)
            {
                if (w1.Length != w2.Length)
                {
                    return false;
                }
                char[] arr1 = w1.ToCharArray();
                char[] arr2 = w2.ToCharArray();
                int count = 0;
                int len = w1.Length;
                for(int j = 0; j < len; j++) 
                {
                    for (int i = 0; i < arr2.Length; i++)
                    {
                        if (arr1[0] == arr2[i])
                        {
                            arr1 = del(arr1, 0);
                            arr2 = del(arr2, i);
                            count++;
                        }
                    }
                }
                if (count == len)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            static char[] del(char[] arr, int n)
            {
                char[] res = new char[arr.Length - 1];
                for (int i = 0, k = 0; i < arr.Length; i++)
                {
                    if (i != n)
                    {
                        res[k] = arr[i];
                        k++;
                    }
                }
                return res;
            }
 static bool Anagram(string w1, string w2)
{
    string result = "";
    for (int i = 0; i < w1.Length; i++)
        for (int j = 0; j < w2.Length; j++)
            if(w1[i] == w2[j]) { result += w1[i] + ""; }
    if(w1 == result) { return true; }
    else { return false; }
}
 static bool Anagram(string w1, string w2) {
    int[] array1 = new int[52];
    int[] array2 = new int[52];
    foreach (char c in w1) array1[c]++;
    foreach (char c in w2) array2[c]++;
    for (int i = 0; i < 52; i++) if (array1[i] != array2[i]) return false;
    return true;
}
 static bool Anagram(string w1, string w2)
    {
        if (w1.Length != w2.Length)
        {
            return false;
        }

        System.Collections.Generic.Dictionary< char, int> dict1 = new System.Collections.Generic.Dictionary< char, int>();

        foreach (char el in w1)
        {
            if (dict1.ContainsKey(el))
            {
                dict1[el] += 1;
            }
            else
            {
                dict1[el] = 1;
            }
        }

        System.Collections.Generic.Dictionary< char, int> dict2 = new System.Collections.Generic.Dictionary< char, int>();
        foreach (char el in w2)
        {
            if (dict2.ContainsKey(el))
            {
                dict2[el] += 1;
            }
            else
            {
                dict2[el] = 1;
            }
        }

        foreach (char el in dict1.Keys)
        {
            int n = 0;
            if (dict2.TryGetValue(el, out n))
            {
                if (n != dict1[el])
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        return true;
    }
 static bool Anagram(string w1, string w2){
if (w1.Length != w2.Length) {
            return false;
        }
        int[] count1 = new int[256];
        int[] count2 = new int[256];
        for (int i = 0; i < w1.Length; i++) {
            count1[(int)w1[i]]++;
            count2[(int)w2[i]]++;
        }
        for (int i = 0; i < 256; i++) {
            if (count1[i] != count2[i]) {
                return false;
            }
        }
        return true;
    }
 static bool Anagram(string w1, string w2){
    static char[] Remover(char[] arr, int index){
        char[] outp = new char[arr.Length-1];
        bool pushed = false;
        
        for(int i = 0; i < arr.Length; i++){
            if(i != index){
                if(!pushed){outp[i] = arr[i];}
                else {outp[i-1] = arr[i];}
            }
            else {pushed = true;}
        }
        
        return outp;
    }

    w1 = w1.ToLower();
    w2 = w2.ToLower();
    char[] c1 = w1.ToCharArray(), c2 = w2.ToCharArray();
    int j = 0;
    
    if(c1.Length != c2.Length) return false;
    
    for(int i = 0; i < c1.Length; i++){
        while(true){
            if(j == c2.Length) return false;
            
            if(c2[j] == c1[i]){
                c2 = Remover(c2, j);
                break;
            }
            j++;
        }
        j = 0;
    }
    
    return true;
}
 static bool Anagram(string w1, string w2){
    string w3 = w1 + w2;
    int stIn = 0;
    int count = -1;
    char ch;
    if(w1.Length == w2.Length){
        for(int i = 0; i < w3.Length; i++){ 
            ch = w3[i];
            for(;;){ 
                stIn = w3.IndexOf(ch, stIn);
                count++;
                if(stIn == -1 && count % 2 != 0)
                    return false;
                else if(stIn == -1){                        
                    int limit = count / 2;
                    for(int search = 0; search < w2.Length; search++){ 
                        if(w2[search] == ch){
                            count--;
                        }                                
                    }
                    if(count != limit)
                        return false;
                }
                if(stIn == -1)
                    break;
                stIn += 1;
            }
            stIn = 0;
            count = -1;
        }
        return true; 
    }    
    return false; 
}
 static bool Anagram(string w1, string w2)
{
    if (w1.Length != w2.Length) 
    {
        return false;
    }
    
    int[] letters = new int[256]; 
    
    foreach (char c in w1)
    {
        letters[c]++; 
    }
    
    foreach (char c in w2) 
    {
        letters[c]--; 
        if (letters[c] < 0) 
        {
            return false;
        }
    }
    return true;
}
 public static bool Anagram(string s1, string s2){
     if (string.IsNullOrEmpty(s1) || string.IsNullOrEmpty(s2))
        return false;
    if (s1.Length != s2.Length)
        return false;

    foreach (char c in s2)
    {
        int ix = s1.IndexOf(c);
        if (ix >= 0)
            s1 = s1.Remove(ix, 1);
        else
            return false;
    }

    return string.IsNullOrEmpty(s1);
}
 static string Sor(string s)
{
    char[] mass = s.ToCharArray();
    int n = mass.Length;
    for (int i = n - 2; i >= 0; i--)
        for (int j = 0; j <= i; j++)
            if (mass[j + 1] < mass[j])
                (mass[j], mass[j + 1]) = (mass[j + 1], mass[j]);
    return  String.Join("", mass);
}
static bool Anagram(string w1, string w2)
{
    return (Sor(w1) == Sor(w2));
}
 static bool Anagram(string w1, string w2)
{
    if (w1.Length != w2.Length)
    {
        return false;
    }
    else
    {
        char[] wd1 = Sport(w1);
        char[] wd2 = Sport(w2);

        for (int i = 0; i < wd1.Length; i++)
        {
            if (wd1[i] != wd2[i])
            {
                return false;
            }
        }
    }
    return true;
}

static char[] Sport(string str)
{
    char[] arr = str.ToCharArray();
    for (int i = 0; i < arr.Length; i++)
    {
        for (int j = i + 1; j < arr.Length; j++)
        {
            if (arr[i] > arr[j])
            {
                char c = arr[i];
                char d = arr[j];
                arr[i] = d;
                arr[j] = c;
            }
        }

    }
        
    return arr;
}
 static bool Anagram(String w1, String w2)
{
    if (w1.Length != w2.Length)
    {
        return false;
    }

    int[] count = new int[100];
    for (int i = 0; i < w1.Length; i++)
    {
        count[(int)w1[i]]++;
        count[(int)w2[i]]--;
    }

    for (int i = 0; i < count.Length; i++)
    {
        if (count[i] != 0)
        {
            return false;
        }
    }

    return true;
}
 static bool Anagram(string w1, string w2) {
    string str1 = String.Concat(w1.OrderBy(x => x));
    string str2 = String.Concat(w2.OrderBy(x => x));
    return str1 == str2 ? true : false;
}
 static bool Anagram(string w1, string w2) {
    string st1 = String.Concat(w1.OrderBy(i => i));
    string st2 = String.Concat(w2.OrderBy(i => i));

    if (st1 == st2) {
        return true;
    }
    else {
        return false;
    }
}
 static bool Anagram(string w1, string w2)
{
    string a = String.Concat(w1.OrderBy(x => x));
    string b = String.Concat(w2.OrderBy(x => x));
    if (a != b)
    {
        return false;
    }
    else
    {
       return true; 
    }
    
    
}
static bool Anagram(string w1, string w2) {
    if(w1.Length != w2.Length) return false; // Якщо рядки не рівні
    
    for(int i = 0; i < w1.Length; i++) {
        int idx = w2.IndexOf(w1[i]); // Індекс символа
        if(idx == -1) return false; // Якщо символа немає у другому рядку
        w2 = w2.Remove(idx, 1); // Видалення символа
    }
    return true;
}
 static bool Anagram(string w1, string w2)
{
    if (w1.Length == w2.Length) {
    for (int i = 0; i < w1.Length; i += 1) {
        for (int j = 0;j < w1.Length; j+= 1) {
            if (w1[i]== w2[j]) {
                w1 = w1.Remove(i,1);
                w2 = w2.Remove(j,1);
                i -= 1;
                break;
            }
        }
    }
    }
    if (w1.Length == 0 && w2.Length == 0) {
        return true;
    }
    return false;
}
 static bool Anagram(string w1, string w2){
    char[] w01 = w1.ToArray();
    char[] w02 = w2.ToArray();
    char[] w10 = SortArray(w01, 0, w01.Length - 1);
    char[] w20 = SortArray(w02, 0, w02.Length - 1);
    return string.Join(",", w10) == string.Join(",", w20);
}
static char[] SortArray(char[] array, int leftIndex, int rightIndex)
{
    int i = leftIndex;
    int j = rightIndex;
    char pivot = array[leftIndex];
    while (i <= j)
    {
        while (array[i] < pivot)
        {
            i++;
        }
        
        while (array[j] > pivot)
        {
            j--;
        }
        if (i <= j)
        {
            char temp = array[i];
            array[i] = array[j];
            array[j] = temp;
            i++;
            j--;
        }
    }
    
    if (leftIndex < j)
        SortArray(array, leftIndex, j);
    if (i < rightIndex)
        SortArray(array, i, rightIndex);
    return array;
}
 static bool Anagram(string w1, string w2){
    if (w1.Length!=w2.Length){
        return false;
    }
    int[] d= new int[256];
    for (int i=0; i< w1.Length; i++){
        d[(int)w1[i]]++;
        d[(int)w2[i]]--;
    }
    for (int j=0; j< 256; j++){
        if (d[j]!=0){
            return false;
        }
    }
    return true;
}
 static bool Anagram(string w1, string w2)
{
    if (w1.Length == w2.Length)
    {
        int counter = 0;
        char[] w1Arr = new char[w1.Length];
        
        for (int i = 0; i < w1Arr.Length; i++)
            w1Arr[i] = w1[i];
            
        for (int i = 0; i < w2.Length; i++)
        {
            for (int j = 0; j <  w1Arr.Length; j++)
                {
                    if (w2[i] == w1Arr[j])
                    {
                        w1Arr[j] = ' ';
                        counter++;
                        break;
                    }
                }
        }
        return counter == w2.Length;
    }
    return false;
}
 static bool Anagram(string w1, string w2) {
    char[] arr1 = w1.ToCharArray(), arr2 = w2.ToCharArray();
    
    return arr1.OrderBy(n => n).SequenceEqual(arr2.OrderBy(n => n));
}
 static bool Anagram(string w1, string w2)
{
    if (w1.Length != w2.Length)
    {
        return false;
    }

    bool[] used = new bool[w2.Length];

    for (int i = 0; i < w1.Length; i++)
    {
        bool found = false;
        for (int j = 0; j < w2.Length; j++)
        {
            if (!used[j] && w1[i] == w2[j])
            {
                used[j] = true;
                found = true;
                break;
            }
        }
        if (!found)
        {
            return false;
        }
    }
    return true;
}
 static bool Anagram(string w1, string w2) {
    if (w1.Length != w2.Length) return false;
    int[] letters = new int[256];
    for (int i = 0; i < w1.Length; i++) {
        letters[(int)w1[i]]++;
        letters[(int)w2[i]]--;
    }
    for (int i = 0; i < 256; i++)
        if (letters[i] != 0) return false;
    return true;
}
 static bool Anagram(string w1, string w2){
    int sum = 0;
    for (int i = 0; i < w1.Length; i++){
        if (w2.Count(c => c == w1[i])==1){
            sum++;
        }
    }
    if (sum == w2.Length){
        return true;
    }
    else {
        return false;
    }
}