Xeon_GT @ 2021-12-22 20:43:33
#include<iostream>
#include<string>
using namespace std;
string strall;
int n,k;
char t = '0';
int main() {
cin >> strall;
n = strall.length();
for (int i = 1; i < n; i++) {
string strtemp;
cin >> strtemp;
strall = strall + strtemp;
}
int num[100000] = {};
for (int j = 0; j < n * n; j++) {
if (strall[j] == t) {
num[k]++;
}
else {
num[k + 1]++;
k++;
if (t == '0')t = '1';
else t = '0';
}
}
cout << n<<" ";
for (int j = 0; j < n*n; j++) {
if (num[j] != 0) {
cout << num[j]<<" ";
}
}
}
by Xeon_GT @ 2021-12-22 20:50:39
明白了 只有两个ac是没有考虑到当第一个数就是1的情况 以下为改正后ac的代码:
#include<iostream>
#include<string>
using namespace std;
string strall;
int n,k = 0;
char t = '0';
int main() {
cin >> strall;
n = strall.length();
for (int i = 1; i < n; i++) {
string strtemp;
cin >> strtemp;
strall = strall + strtemp;
}
int num[100000] = {};
for (int j = 0; j < n * n; j++) {
if (strall[j] == t) {
num[k]++;
}
else {
num[k + 1]++;
k++;
if (t == '0')t = '1';
else t = '0';
}
}
cout << n<<" ";
if (num[0] == 0) {
cout << "0 ";
}
for (int j = 0; j < n*n; j++) {
if (num[j] != 0) {
cout << num[j]<<" ";
}
}
return 0;
}
by Lantrol @ 2021-12-22 20:56:52
建议自删,讨论区别发标程()