summaryrefslogtreecommitdiffstats
path: root/Main/C++/2018/S2.cpp
blob: 7b5f4d3b9463c0f2b8aa97189ce5990d53628c0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
bool is_correct(vector<vector<int>> table, int n);
vector<vector<int>> rotate_table(vector<vector<int>> table, int n);
void print_table(vector<vector<int>> table, int n);

int main()
{
    int N, input;
    cin >> N;
    vector<vector<int>> data;
    for (int i = 0; i < N; i++)
    {
        vector<int> line;
        for (int j = 0; j < N; j++)
        {
            cin >> input;
            line.push_back(input);
        }
        data.push_back(line);
    }


    for (int i = 0; i < 3; i++)
    {
        if (is_correct(data,N)==true)
            break;
        else
            data = rotate_table(data, N);
    }

    print_table(data, N);
}

void print_table(vector<vector<int>> table, int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << table[i][j] << ' ';
        }
        cout << endl;
    }
}


vector<vector<int>> rotate_table(vector<vector<int>> table, int n)
{
    vector<vector<int>> output;
    for (int i = 0; i < n; i++)
    {
        vector<int> row;
        for (int j = 0; j < n; j++)
        {
            row.push_back(table[j][i]);
        }
        reverse(row.begin(), row.end());
        output.push_back(row);
    }
    return output;
}


bool is_correct(vector<vector<int>> table, int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j < n; j++)
        {
            if (table[i][j] < table[i][j-1])
                return false;
            else if (table[j][i] < table[j-1][i])
                return false;
        }
    }

    return true;
}