Данный отчёт сгенерирован 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
Описание: Вже оголошено структуру struct Struct { public int Key; public string Value; } Оголосити статичний метод Struct[] Merge (Struct[] s1,Struct[] s2), який зливає два впорядковані масиви структур у третій, теж упорядкований. Елементи масивів розташовані за зростанням ключів. 04.04.2023 06:21:13
Решений: 31 04.04.2023 06:21:13
Злиття Упорядкованих Масивів 04.04.2023 06:21:13
 static Struct[] Merge(Struct[] s1, Struct[] s2)
{
    return s1.Concat(s2).OrderBy(x=>x.Key).ToArray();
}
 static Struct[] Merge(Struct[] s1,Struct[] s2){
    Struct[] a=new Struct[s1.Length+s2.Length];
    for(int i=0;i< s1.Length;i++){
        a[i]=s1[i];
    }
    for(int j=s1.Length;j< s2.Length;j++){
        a[j]=s2[j-s1.Length];
    }
    return a;
}
static Struct[] Merge (Struct[] s1, Struct[] s2) {
    Struct[] res = new Struct[s1.Length+s2.Length-2];
    for(int i = 0, j = 0; i < s1.Length && j < s2.Length;) {
        if(s1[i].Key < s2[j].Key) {
            res[i+j] = s1[i];
            i++;
        } else {
            res[i+j] = s2[j];
            j++;
        }
    }
    return res;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2) => s1.Concat(s2).ToArray();
 static Struct[] Merge(Struct[] s1, Struct[] s2)
    {
        Struct[] s3 = new Struct[s1.Length + s2.Length];
        int r = 0;
        int i , j;

        for ( i=0,j=0; i < s1.Length && j < s2.Length; r++ )
        {
            if (s1[i].Key< s2[j].Key)
            {
                s3[r]= s1[i];
                //j--;
                i++;
            }
            if (s2[j].Key < s1[i].Key)
            {
                s3[r] = s2[j];
                //i--;
                j++;
            }

        }
        if(s1.Length!= s2.Length)
        {
            while(i< s1.Length-1)
            {
                s3[r] = s1[i];
                i++;
                r++;

            }
            while (j < s2.Length-1)
            {
                s3[r] = s2[j];
                j++;
                r++;

            }
        }
        return s3;
    }
 static Struct[] Merge (Struct[] s1,Struct[] s2){
    Struct[] result = new Struct[s1.Length + s2.Length];
    int n = 0, i = 0, j = 0;
    while (i < s1.Length && j < s2.Length)
    {
        if (s1[i].Key < s2[j].Key)
        {
            result[n] = s1[i];
            n++;
            i++;
        }
        else
        {
            result[n] = s2[j];
            n++;
            j++;
        }
        if (i == s1.Length) { Array.Copy(s2, j, result, n, s2.Length - j); }
        if (j == s2.Length) { Array.Copy(s1, i, result, n, s1.Length - i); }
    }
    return result;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2)
{
    Struct[] res = new Struct[s1.Length + s2.Length];
    int p1 = 0;
    int p2 = 0;
    for (int i = 0; i < res.Length; i++)
    {
        if (p2 == s2.Length || s1[p1].Key <= s2[p2].Key)
        {
            res[i] = s1[p1];
            p1++;
        }
        else if (p1 == s1.Length)
        {
            res[i] = s2[p2];
            p2++;
        }
    }
    return res;
}
 static Struct[] Merge(Struct[] s1, Struct[] s2)
{
    return s1.Concat(s2).OrderBy(x=>x.Key).ToArray();
}
 static Struct[] Merge (Struct[] s1,Struct[] s2) {
    return s1.Concat(s2).ToArray();
}
 static Struct[] Merge(Struct[] s1, Struct[] s2) {
    Struct[] result = new Struct[s1.Length + s2.Length];
    int i = 0, j = 0, k = 0;

    while (i < s1.Length && j < s2.Length) {
        if (s1[i].Key < s2[j].Key) result[k++] = s1[i++];
        else result[k++] = s2[j++];
    }
    
    return result;
}
 static Struct[] Merge(Struct[] s1, Struct[] s2)
{
    Struct[] result = new Struct[s1.Length + s2.Length];
    int i = 0, j = 0, k = 0;

    while (i < s1.Length && j < s2.Length)
    {
        if (s1[i].Key <= s2[j].Key)
        {
            result[k] = s1[i];
            i++;
        }
        else
        {
            result[k] = s2[j];
            j++;
        }
        k++;
    }
    while (i < s1.Length)
    {
        result[k] = s1[i];
        i++;
        k++;
    }
    while (j < s2.Length)
    {
        result[k] = s2[j];
        j++;
        k++;
    }
    return result;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2){
    return s1.Concat(s2).ToArray();
}
 static Struct[] Merge(Struct[] s1, Struct[] s2) {
        Struct[] merged = new Struct[s1.Length + s2.Length];
        int i = 0, j = 0, k = 0;
        while (i < s1.Length && j < s2.Length) {
            if (s1[i].Key < s2[j].Key) {
                merged[k++] = s1[i++];
            } else {
                merged[k++] = s2[j++];
            }
        }
        while (i < s1.Length) {
            merged[k++] = s1[i++];
        }
        while (j < s2.Length) {
            merged[k++] = s2[j++];
        }
        return merged;
    
}
 static Struct[] Merge (Struct[] s1,Struct[] s2){
    Struct[] s = new Struct[s1.Length + s2.Length];
    s1.CopyTo(s, 0);
    s2.CopyTo(s, s1.Length);
    
    for(int i = 0; i < s.Length; i++)
    for(int j = s.Length-1; j > 0; j--){
        if(s[j].Key < s[j-1].Key){
            var temp = s[j];
            s[j] = s[j-1];
            s[j-1] = temp;
        }
    }
    return s;
}
 static Struct[] Merge(Struct[] s1, Struct[] s2)
    {
        Struct[] ss = new Struct[s1.Length + s2.Length];
        int s1index = 0;
        int s2index = 0;
        for (int i = 0; i < ss.Length; i++)
        {
            if(s2index >=s2.Length)
            {
                for(int q = s1index;q< s1.Length;q++)
                {
                    ss[i] = s1[q];
                    i++;
                }
                break;
            }
            if (s1index >= s1.Length)
            {
                for (int q = s2index; q < s2.Length; q++)
                {
                    ss[i] = s2[q];
                    i++;
                }
                break;
            }
            if (s1[s1index].Key <= s2[s2index].Key)
            {
                ss[i] = s1[s1index];
                s1index++;
            }
            else
            {
                ss[i] = s2[s2index];
                s2index++;

            }

        }
        return ss;
    }
 static Struct[] Merge (Struct[] s1,Struct[] s2)
{
    Struct[] s3 = new Struct[s1.Length + s2.Length];
    for(int i = 0; i < s3.Length; i += 1)
    {
        foreach(Struct item1 in s1)
        {
            foreach(Struct item2 in s2)
            {
                if(i % 2 == 0)
                  s3[i] = item1;
                else
                  s3[i] = item2;
            }
        }
    }
    return s3;
}
 static Struct[] Merge (Struct[] arr1,Struct[] arr2)
{
    Struct[] result = new Struct[arr1.Length + arr2.Length];
    for(int i = 0; i < arr1.Length; i++) 
        result[i] = arr1[i];
    for(int i = 0; i < arr2.Length; i++) 
        result[arr1.Length + i] = arr2[i];
        
    // Сортировка шейкером
    int left = 0, right = result.Length - 1;
    while (left <= right)
    {
        for (int i = right; i > left; i--)
        {
            if (result[i - 1].Key > result[i].Key)
                (result[i - 1], result[i]) = (result[i], result[i - 1]);
        }
        ++left;
        for (int i = left; i < right; i++)
        {
            if (result[i].Key > result[i + 1].Key)
                (result[i], result[i + 1]) = (result[i + 1], result[i]);
        }
        --right;
    }
    return result;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2){
    int leftSize = s1.Length;
    int rightSize = s2.Length;
    Struct [] s3 = new Struct[leftSize + rightSize];
    int i = 0, l = 0, r = 0;
    while(l < leftSize && r < rightSize){
        if(s1[l].Key < s2[r].Key){
            s3[i] = s1[l];
            i++;
            l++;
        }
        else{
            s3[i] = s2[r];
            i++;
            r++;
        }
    }
    while (l < leftSize){
        s3[i] = s1[l];
        i++;
        l++;
    }
    while (r < rightSize){
        s3[i] = s2[r];
        i++;
        r++;
    }
    return s3;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2)
{
    Struct[] s3 = new Struct[s1.Length + s2.Length];
    int index = 0;
    for ( int i = 0; i < s1.Length; i++)
    {
        for ( int j = i; j < s2.Length && s1[i].Key > s2[j].Key ; j ++)
        {
            s3[index] = s2[j];
            index ++;
        }
        s3[index] = s1[i];
        index++;
    }
    return s3;
}
 static Struct[] Merge(Struct[] s1,Struct[] s2){
    Struct[] answ = new Struct[s1.Length+s2.Length];
    int c = 0;
    
    if(s1[0].Key < s2[0].Key){
        foreach(var item in s1) {answ[c] = item; c++;}
        foreach(var item in s2) {answ[c] = item; c++;}
    }
    else{
        foreach(var item in s1) {answ[c] = item; c++;}
        foreach(var item in s2) {answ[c] = item; c++;}
    }
    return answ;
}
 static Struct[] Merge (Struct[] s1, Struct[] s2) {
    Struct[] result = new Struct[s1.Length + s2.Length];
    int s1Pointer = 0;
    int s2Pointer = 0;
    for (int i = 0; i < result.Length; i++) {
        if (s1Pointer < s1.Length && (s2Pointer >= s2.Length || s1[s1Pointer].Key < s2[s2Pointer].Key)) {
            result[i] = s1[s1Pointer];
            s1Pointer++;
        } else {
            result[i] = s2[s2Pointer];
            s2Pointer++;
        }
    }
    return result;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2)
{
    Struct[] s3 = new Struct[s1.Length + s2.Length];
    int i = 0, j = 0, k = 0; 
    for (; j < s1.Length && k < s2.Length; i++)
    {
        if (s1[j].Key > s2[k].Key)
        {
            s3[i] = s2[k];
            k++;
        }
        else 
        {
            s3[i] = s1[j];
            j++;
        }
    }
    while (j < s1.Length)
    {
        s3[i] = s1[j];
        i++;
        j++;
    }
    while (k < s2.Length)
    {
        s3[i] = s2[k];
        i++;
        k++;
    }
    return s3;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2)
{
    Struct[] s3 = new Struct[s1.Length + s2.Length];
    foreach (Struct s1structure in s1)
    {
        foreach (Struct s2structure in s2)
        {
            
        }
    }
    return s3;
}

//Starege
 static Struct[] Merge(Struct[] s1, Struct[] s2) {
    int i = 0;
    int j = 0;
    int l1 = s1.Length;
    int l2 = s2.Length;
    bool takeFromS1 = true;
    Struct[] arr = new Struct[l1 + l2];
    
    for (int k = 0; k < arr.Length; k++) {
        if(i>= l1) {
            takeFromS1 = false;
        }
        else if (j>= l2) {
            takeFromS1 = true;
        }

        else if (s1[i].Key > s2[j].Key) {
            takeFromS1 = false;
        }

        arr[k] = takeFromS1 ? s1[i++] : s2[j++];
    }

    return arr;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2){
    Struct[] result = new Struct[s1.Length + s2.Length];

    int i = 0, j = 0, k = 0;
    while (i < s1.Length && j < s2.Length) {
        if (s1[i].Key < s2[j].Key) {
            result[k++] = s1[i++];
        }
        else {
            result[k++] = s2[j++];
        }
    }

    while (i < s1.Length) {
        result[k++] = s1[i++];
    }

    while (j < s2.Length) {
        result[k++] = s2[j++];
    }

    return result;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2)
{
    Struct[] s = new Struct[s1.Length + s2.Length];
    Array.Copy(s1,s,s1.Length);
    Array.Copy(s2,s,s2.Length);
    Array.Sort(s, (s1, s2) => s1.Key.CompareTo(s2.Key));
    return s;
}
 static Struct[] Merge(Struct[] s1, Struct[] s2)
{
    Struct[] result = new Struct[s1.Length + s2.Length];
    int i = 0, j = 0, k = 0;

    while (i < s1.Length && j < s2.Length)
    {
        if (s1[i].Key < s2[j].Key)
            result[k++] = s1[i++];
        else
            result[k++] = s2[j++];
    }

    while (i < s1.Length)
        result[k++] = s1[i++];

    while (j < s2.Length)
        result[k++] = s2[j++];

    return result;
}
 static Struct[] Merge(Struct[] s1, Struct[] s2)
        {
            Struct[] ss = new Struct[s1.Length + s2.Length];
            for(int i=0,  cs1=0, cs2 = 0; i < ss.Length; i++)
            {
                if (cs2 < s2.Length && cs1 < s1.Length) {
                    if (s1[cs1].Key > s2[cs2].Key )
                    {
                        ss[i].Key = s2[cs2].Key;
                        cs2++;
                    }
                    else if (s1[cs1].Key <= s2[cs2].Key )
                    {
                        ss[i].Key = s1[cs1].Key;
                        cs1++;

                    }
                }
                else if(cs2 >=s2.Length)
                {
                    ss[i].Key = s1[cs1].Key;
                    cs1++;
                }
                else if(cs1 >= s1.Length)
                {
                    ss[i].Key = s2[cs2].Key;
                    cs2++;
                }
                
            }
            return ss;
        }
 static Struct[] Merge(Struct[] s1, Struct[] s2)
{
    Struct[] result = new Struct[s1.Length + s2.Length];

    int i = 0;
    int j = 0;
    int k = 0;

    while (i < s1.Length && j < s2.Length)
    {
        if (s1[i].Key <= s2[j].Key)
        {
            result[k] = s1[i];
            i++;
        }
        else
        {
            result[k] = s2[j];
            j++;
        }
        k++;
    }

    while (i < s1.Length)
    {
        result[k] = s1[i];
        i++;
        k++;
    }

    while (j < s2.Length)
    {
        result[k] = s2[j];
        j++;
        k++;
    }

    return result;
}
 static Struct[] Merge (Struct[] s1,Struct[] s2) {
Struct[] s3 = new Struct[s1.Length + s2.Length];
    for(int i = 0, j = 0; i < s1.Length && j < s2.Length;){
        if(s1[i].Key >= s2[j].Key) s3[i+j] = s2[j++];
        else s3[i+j] = s1[i++];
    }
    return s3;
}
// чому тсс прийняв цей код? не знаю)
 static Struct[] Merge (Struct[] s1,Struct[] s2){
    Struct[] s3 = new Struct[s1.Length + s2.Length];
    s1.CopyTo(s3, 0);
    s2.CopyTo(s3, s1.Length);
    Array.Sort(s3, (x, y) => x.Key.CompareTo(y.Key));
    return s3;
}