Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- using namespace std;
- int mas[500][500] = {0};
- int c = 0, q = 1;
- int n;
- void solve1(int i, int j)
- {
- int l = -1, cl = 0, u = 1, cnt = 0, kk = -1, oo = -2;
- bool f = 1;
- while (cnt < n * n)
- {
- cout << mas[i][j] << ' ';
- l++;
- cnt++;
- if (cl == l)
- {
- i += kk;
- j += oo;
- kk--;
- u += 2;
- cl += u;
- cout << endl;
- }
- else
- {
- if (f)
- {
- i++;
- j++;
- f = !f;
- }
- else
- {
- j--;
- f = !f;
- }
- }
- }
- }
- int line[200000] = {0};
- void solve2(int i, int j)
- {
- int l = -1, cl = 0, u = 1, cnt = 0, kk = -1, oo = -2;
- bool f = 1;
- while (cnt < n * n)
- {
- line[cnt] = mas[i][j];
- l++;
- cnt++;
- if (cl == l)
- {
- i += kk;
- j += oo;
- kk--;
- u += 2;
- cl += u;
- //cout << endl;
- }
- else
- {
- if (f)
- {
- i++;
- j++;
- f = !f;
- }
- else
- {
- j--;
- f = !f;
- }
- }
- }
- }
- void solve3()
- {
- int c = 0, q = 1, i = 0, j = 0;
- for (int k = 0; k < n * n; k++)
- {
- mas[j][c++] = line[k];
- if (c == q)
- {
- q += 2;
- c = 0;
- j++;
- }
- }
- int l = -1, cl = 0, u = 1, cnt = 0, kk = -1, oo = -2;
- bool f = 1;
- i = j - 1;
- j = q - 3;
- while (cnt < n * n)
- {
- cout << mas[i][j] << ' ';
- l++;
- cnt++;
- if (cl == l)
- {
- i += kk;
- j += oo;
- kk--;
- u += 2;
- cl += u;
- cout << endl;
- }
- else
- {
- if (f)
- {
- i++;
- j++;
- f = !f;
- }
- else
- {
- j--;
- f = !f;
- }
- }
- }
- }
- int main()
- {
- freopen("triangle.in", "r", stdin);
- freopen("triangle.out", "w", stdout);
- cin >> n;
- int j = 0;
- for (int k = 0; k < n * n; k++)
- {
- cin >> mas[j][c++];
- if (c == q)
- {
- q += 2;
- c = 0;
- j++;
- }
- }
- string s;
- cin >> s;
- if (s == "counterclockwise")
- {
- solve1(j - 1, q - 3);
- }
- else
- {
- solve2(j - 1, q - 3);
- solve3();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement