只有20分,但是自己试了很多个例子都能过
查看原帖
只有20分,但是自己试了很多个例子都能过
974333
wsad8241808楼主2024/2/29 21:34
#include <iostream>
#include <string>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;

int main() {
	int n;
	int b[50000];   //存放第二个以后得输入数字
	memset(b, -1, sizeof(b));
	bool c = 0;
	int sum = 0;
	int i = 0, j = 0;
	cin >> n;
	while (sum < n * n) { //当输入的数字总和大于等于n^2的时候停止。
		cin >> b[i];
		sum += b[i++];
	}
	for (int i = 0; i < n * n; i++) {
		cout << c;		//输出0或者1
		b[j]--;			//对于连续输出的0或者1计数,等于0时跳到下一个数字,并且输出的0和1互换
		if (b[j] == 0) {
			j++;
			c = !c;
		}
		if (i % n == n - 1) {	//输出n-1个数字之后换行;
			cout << endl;
		}
	}
	return 0;
}
2024/2/29 21:34
加载中...