求助,全是re和wa,re调试等问题小白求助!!!
查看原帖
求助,全是re和wa,re调试等问题小白求助!!!
675527
Play_CP_4fun楼主2022/4/3 13:17
#include <bits/stdc++.h>
using namespace std;
int ans[300][300], n, cnt, mark[100000];

void core_solution(int a[], int cnt1, int n1) {
	int hang = 0, lie = 0, out = 0;
	for (int i = 0; i < cnt1; i++) {
		while (a[i]--) {
			ans[hang][lie++] = out;
			if (lie > n1 - 1) {
				hang += 1;
				lie = 0;
			}
		}
		if (out == 0) out = 1;
		else out = 0;
	}
}
int main() { 
	cin >> n;
	string s;
	getline(cin ,s);
	cout << n << s;
	for (int i = 0; s[i] != '\0'; i++) {
		if (s[i] != ' ') 
			mark[cnt++] = s[i] - '0';
	}
	
	core_solution (mark, cnt, n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << ans[i][j];
		}
		cout << "\n";
	}
	return 0;
}

样例都能过,为啥全是re和wa,数组好像也没越界,是getline那行有问题吗。

还有本若菜想请教一下读入一串不知道长度的数字还有什么好方法吗

2022/4/3 13:17
加载中...