colin526 @ 2024-05-03 19:51:01
测试全对,提交WA,求巨佬帮忙。
我的主要思路是
1.把“000000...”用 char 输入
#include<bits/stdc++.h>
using namespace std;
int n , l , sum;
char a[40001];
int main(){
scanf("%s" , a + 1);
l = strlen(a + 1);
n = sqrt(l);
printf("%d " , n);
for(int i = 2; i <= l + 1; i++){
if(a[i] == a[i - 1]){
sum++;
}
else{
sum++;
printf("%d " , sum);
sum = 0;
}
}
}
球球了
by lzmh_zwb @ 2024-06-29 20:13:44
@colin526 你这样读入字符数组就已经不行了
这样写只能读入第一行,剩下的读不进去
最好换一下输入方式读入完整了再处理
by 123huchenghao @ 2024-06-30 18:24:26
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
string a[N];
int sum;
int main() {
cin >> a[0];
int n = a[0].size();
for (int i = 1; i < n; i++) cin >> a[i];
printf("%d ", n);
char cur = '0';
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (a[i][j] == cur) sum++;
else {
printf("%d ", sum);
if (cur == '0') cur = '1'; else cur = '0';
sum = 1;
}
printf("%d ", sum);
return 0;
}