萌新刚学 OI,WA 了,自己代码这么简单也不知道会在哪里出错所以求助 QAQ
查看原帖
萌新刚学 OI,WA 了,自己代码这么简单也不知道会在哪里出错所以求助 QAQ
298549
SIXIANG32楼主2022/12/29 15:42

如题,代码相当清新,题目也很简单,但是写挂了,求助 awa

//SIXIANG
#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;
}
2022/12/29 15:42
加载中...