Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Помогите упростить)

IDA
Пользователь
Пользователь
Статус
Оффлайн
Регистрация
16 Мар 2017
Сообщения
261
Реакции
67
C++:
Expand Collapse Copy
#include<iostream>
#include<ctime>

using namespace std;

void Int(int ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
        }
    }  
}

void shou(int ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
}

void shou1(double ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
}

void shou2(char ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
}

void minmax(int ar[][5], int str)
{
    int min = ar[0][0];
    int max = ar[0][0];
    int indexmin = 0;
    int indexmax = 0;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
            if (i == j)
            {
                if (ar[i][j] < min);
                {
                    min = ar[i][j];
                    indexmin = i,j;
                }
                if (ar[i][j] > max)
                {
                    max = ar[i][j];
                    indexmax = i, j;
                }
            }
        }
        cout << endl << endl;
    }
    cout << "min el " << min << endl;
    cout << "max el " << max << endl;
}

void minmax1(double ar[][5], int str)
{
    double min = ar[0][0];
    double max = ar[0][0];
    double indexmin = 0;
    double indexmax = 0;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
            if (i == j)
            {
                if (ar[i][j] < min);
                {
                    min = ar[i][j];
                    indexmin = i, j;
                }
                if (ar[i][j] > max)
                {
                    max = ar[i][j];
                    indexmax = i, j;
                }
            }
        }
        cout << endl << endl;
    }
    cout << "min el " << min << endl;
    cout << "max el " << max << endl;
}

void minmax2(char ar[][5], int str)
{
    char min = ar[0][0];
    char max = ar[0][0];
    char indexmin = 0;
    char indexmax = 0;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
            if (i == j)
            {
                if (ar[i][j] < min);
                {
                    min = ar[i][j];
                    indexmin = i, j;
                }
                if (ar[i][j] > max)
                {
                    max = ar[i][j];
                    indexmax = i, j;
                }
            }
        }
        cout << endl << endl;
    }
    cout << "min el " << min << endl;
    cout << "max el " << max << endl;
}


void vozrast(int ar[][5], int str)
{
    cout << "до сортировки: " << endl;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
    int c, v,i, j,x,z;
    for (c = 0; c <= (str * 5); c++)
    {
        for (i = 0; i < str; i++)
        {
            for (j = 0; j < 5 - 1; j++)
            {
                if (ar[i][j] > ar[i][j + 1])
                {
                    v = ar[i][j];
                    ar[i][j] = ar[i][j + 1];
                    ar[i][j + 1] = v;
                }
            }
        }
        for (x = 0; x < 5; x++)
        {
            for (z = 0; z < str - 1; z++)
            {
                if (ar[z][x] > ar[z][x + 1])
                {
                    v = ar[z][x];
                    ar[z][x] = ar[z][x + 1];
                    ar[z][x + 1] = v;
                }
            }
        }
    }
    cout << "отсортировал: " << endl;
    for (i = 0; i < str; i++)
    {
        for (j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl;
    }
}

void vozrast1(double ar[][5], int str)
{
    cout << "до сортировки: " << endl;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
    double c, v;
    int i, j, x, z;
    for (c = 0; c <= (str * 5); c++)
    {
        for (i = 0; i < str; i++)
        {
            for (j = 0; j < 5 - 1; j++)
            {
                if (ar[i][j] > ar[i][j + 1])
                {
                    v = ar[i][j];
                    ar[i][j] = ar[i][j + 1];
                    ar[i][j + 1] = v;
                }
            }
        }
        for (x = 0; x < 5; x++)
        {
            for (z = 0; z < str - 1; z++)
            {
                if (ar[z][x] > ar[z][x + 1])
                {
                    v = ar[z][x];
                    ar[z][x] = ar[z][x + 1];
                    ar[z][x + 1] = v;
                }
            }
        }
    }
    cout << "отсортировал: " << endl;
    for (i = 0; i < str; i++)
    {
        for (j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl;
    }
}
void vozrast2(char ar[][5], int str)
{
    cout << "до сортировки: " << endl;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
    char c, v, i, j, x, z;
    for (c = 0; c <= (str * 5); c++)
    {
        for (i = 0; i < str; i++)
        {
            for (j = 0; j < 5 - 1; j++)
            {
                if (ar[i][j] > ar[i][j + 1])
                {
                    v = ar[i][j];
                    ar[i][j] = ar[i][j + 1];
                    ar[i][j + 1] = v;
                }
            }
        }
        for (x = 0; x < 5; x++)
        {
            for (z = 0; z < str - 1; z++)
            {
                if (ar[z][x] > ar[z][x + 1])
                {
                    v = ar[z][x];
                    ar[z][x] = ar[z][x + 1];
                    ar[z][x + 1] = v;
                }
            }
        }
    }
    cout << "отсортировал: " << endl;
    for (i = 0; i < str; i++)
    {
        for (j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl;
    }
}

void main()
{
    setlocale(0, "ru");
    srand(time(0));
    int mas[5][5];
    double mas1[5][5];
    char mas2[5][5];
    Int(mas, 5);
    shou(mas, 5);
    cout << endl;
    shou1(mas1, 5);
    cout << endl;
    shou2(mas2, 5);
    minmax(mas, 5);
    cout << endl;
    minmax1(mas1, 5);
    cout << endl;
    minmax2(mas2, 5);
    vozrast(mas, 5);
    cout << endl;
    vozrast1(mas1, 5);
    cout << endl;
    vozrast2(mas2, 5);

    system("pause");
}
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
C++:
Expand Collapse Copy
#include<iostream>
#include<ctime>

using namespace std;

void Int(int ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
        }
    }
}

void shou(int ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
}

void shou1(double ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
}

void shou2(char ar[][5], int str)
{
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
}

void minmax(int ar[][5], int str)
{
    int min = ar[0][0];
    int max = ar[0][0];
    int indexmin = 0;
    int indexmax = 0;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
            if (i == j)
            {
                if (ar[i][j] < min);
                {
                    min = ar[i][j];
                    indexmin = i,j;
                }
                if (ar[i][j] > max)
                {
                    max = ar[i][j];
                    indexmax = i, j;
                }
            }
        }
        cout << endl << endl;
    }
    cout << "min el " << min << endl;
    cout << "max el " << max << endl;
}

void minmax1(double ar[][5], int str)
{
    double min = ar[0][0];
    double max = ar[0][0];
    double indexmin = 0;
    double indexmax = 0;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
            if (i == j)
            {
                if (ar[i][j] < min);
                {
                    min = ar[i][j];
                    indexmin = i, j;
                }
                if (ar[i][j] > max)
                {
                    max = ar[i][j];
                    indexmax = i, j;
                }
            }
        }
        cout << endl << endl;
    }
    cout << "min el " << min << endl;
    cout << "max el " << max << endl;
}

void minmax2(char ar[][5], int str)
{
    char min = ar[0][0];
    char max = ar[0][0];
    char indexmin = 0;
    char indexmax = 0;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
            if (i == j)
            {
                if (ar[i][j] < min);
                {
                    min = ar[i][j];
                    indexmin = i, j;
                }
                if (ar[i][j] > max)
                {
                    max = ar[i][j];
                    indexmax = i, j;
                }
            }
        }
        cout << endl << endl;
    }
    cout << "min el " << min << endl;
    cout << "max el " << max << endl;
}


void vozrast(int ar[][5], int str)
{
    cout << "до сортировки: " << endl;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
    int c, v,i, j,x,z;
    for (c = 0; c <= (str * 5); c++)
    {
        for (i = 0; i < str; i++)
        {
            for (j = 0; j < 5 - 1; j++)
            {
                if (ar[i][j] > ar[i][j + 1])
                {
                    v = ar[i][j];
                    ar[i][j] = ar[i][j + 1];
                    ar[i][j + 1] = v;
                }
            }
        }
        for (x = 0; x < 5; x++)
        {
            for (z = 0; z < str - 1; z++)
            {
                if (ar[z][x] > ar[z][x + 1])
                {
                    v = ar[z][x];
                    ar[z][x] = ar[z][x + 1];
                    ar[z][x + 1] = v;
                }
            }
        }
    }
    cout << "отсортировал: " << endl;
    for (i = 0; i < str; i++)
    {
        for (j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl;
    }
}

void vozrast1(double ar[][5], int str)
{
    cout << "до сортировки: " << endl;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
    double c, v;
    int i, j, x, z;
    for (c = 0; c <= (str * 5); c++)
    {
        for (i = 0; i < str; i++)
        {
            for (j = 0; j < 5 - 1; j++)
            {
                if (ar[i][j] > ar[i][j + 1])
                {
                    v = ar[i][j];
                    ar[i][j] = ar[i][j + 1];
                    ar[i][j + 1] = v;
                }
            }
        }
        for (x = 0; x < 5; x++)
        {
            for (z = 0; z < str - 1; z++)
            {
                if (ar[z][x] > ar[z][x + 1])
                {
                    v = ar[z][x];
                    ar[z][x] = ar[z][x + 1];
                    ar[z][x + 1] = v;
                }
            }
        }
    }
    cout << "отсортировал: " << endl;
    for (i = 0; i < str; i++)
    {
        for (j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl;
    }
}
void vozrast2(char ar[][5], int str)
{
    cout << "до сортировки: " << endl;
    for (int i = 0; i < str; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ar[i][j] = rand() % 20;
            cout << ar[i][j] << "\t";
        }
        cout << endl << endl;
    }
    char c, v, i, j, x, z;
    for (c = 0; c <= (str * 5); c++)
    {
        for (i = 0; i < str; i++)
        {
            for (j = 0; j < 5 - 1; j++)
            {
                if (ar[i][j] > ar[i][j + 1])
                {
                    v = ar[i][j];
                    ar[i][j] = ar[i][j + 1];
                    ar[i][j + 1] = v;
                }
            }
        }
        for (x = 0; x < 5; x++)
        {
            for (z = 0; z < str - 1; z++)
            {
                if (ar[z][x] > ar[z][x + 1])
                {
                    v = ar[z][x];
                    ar[z][x] = ar[z][x + 1];
                    ar[z][x + 1] = v;
                }
            }
        }
    }
    cout << "отсортировал: " << endl;
    for (i = 0; i < str; i++)
    {
        for (j = 0; j < 5; j++)
        {
            cout << ar[i][j] << "\t";
        }
        cout << endl;
    }
}

void main()
{
    setlocale(0, "ru");
    srand(time(0));
    int mas[5][5];
    double mas1[5][5];
    char mas2[5][5];
    Int(mas, 5);
    shou(mas, 5);
    cout << endl;
    shou1(mas1, 5);
    cout << endl;
    shou2(mas2, 5);
    minmax(mas, 5);
    cout << endl;
    minmax1(mas1, 5);
    cout << endl;
    minmax2(mas2, 5);
    vozrast(mas, 5);
    cout << endl;
    vozrast1(mas1, 5);
    cout << endl;
    vozrast2(mas2, 5);

    system("pause");
}
ля, а как ваше код обфусковать как ты сделал ))
 
ля, а как ваше код обфусковать как ты сделал ))
Вот я смотрю и такое чувство, что можно привести этот код в более красивый и слаженный вид, но как это сделать - iq ещё не вырос )
 
Назад
Сверху Снизу