如题,代码相当清新,题目也很简单,但是写挂了,求助 awa
#include <iostream>
#define MAXN 100000
#define QWQ cout << "QWQ" << endl;
using namespace std;
int n, a[MAXN + 10], ans[MAXN + 10], top = 0;
void work() {
top = 0;
for(int i = 1; i < n; i++) {
for(int head = n; head >= 1; head--) {
ans[++top] = 2;
if(a[head] > a[head + 1] && head != n) {
swap(a[head], a[head + 1]);
ans[++top] = 1;
}
}
}
for(int p = top; p >= 1; p--)
cout << ans[p];
cout << endl;
}
int init() {
cin >> n;
if(!n) return -1;
for(int p = 1; p <= n; p++)
cin >> a[p];
work();
return 1;
}
int main() {
while(1)
if(init() < 0) return 0;
}