Task: | Järjestäminen |
Sender: | caro |
Submission time: | 2021-01-23 19:45:15 +0200 |
Language: | C++ (C++11) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:59:21: error: redeclaration of 'int as' int as = t[n - 2]; ^~ input/code.cpp:51:21: note: 'int as' previously declared here int as = t[np]; ^~ input/code.cpp:63:21: error: redeclaration of 'int bs' int bs = t[n - 1]; ^~ input/code.cpp:55:21: note: 'int bs' previously declared here int bs = t[np + 1]; ^~
Code
#include <bits/stdc++.h> using namespace std; int main(){ int num; cin >> num; for(int i = 0; i < num; i++){ int n; cin >> n; int t[n]; int sorted = 1; for(int i = 0; i < n; i++){ cin >> t[i]; if(i > 0) { if(t[i - 1] > t[i]) sorted = 0; } } if(sorted){ printf("YES\n"); continue; } else if(!sorted && n < 4){ printf("NO\n"); continue; } for(int j = 0; j < n - 4; j++){ int np; for(int k = j; k < n; k++){ if(t[k] == j + 1) np = k; } if(np == n - 1){ int as = t[n - 1]; t[n - 1] = t[n - 3]; t[n - 3] = as; int bs = t[n - 2]; t[n - 2] = t[n - 4]; t[n - 4] = bs; int cs = t[n - 3]; t[n - 3] = t[j]; t[j] = cs; int ds = t[n - 2]; t[n - 2] = t[j + 1]; t[j + 1] = ds; } else if(np == j){ } else if(np == j + 1){ int as = t[np]; t[np] = t[n - 2]; t[n - 2] = as; int bs = t[np + 1]; t[np + 1] = t[n - 1]; t[n - 1] = bs; int as = t[n - 2]; t[n - 2] = t[j]; t[j] = as; int bs = t[n - 1]; t[n - 1] = t[j + 1]; t[j + 1] = bs; } else { int as = t[np]; t[np] = t[j]; t[j] = as; int bs = t[np + 1]; t[np + 1] = t[j + 1]; t[j + 1] = bs; } } if((t[n - 4] < t[n - 3] && t[n - 3] < t[n - 2] && t[n - 2] < t[n - 1]) || (t[n - 4] < t[n - 3] && t[n - 1] < t[n - 4] && t[n - 2] < t[n - 1])) printf("YES\n"); else printf("NO\n"); } return 0; }