hsy0824 @ 2024-08-01 02:41:58
#include <bits/stdc++.h>
using namespace std;
int main(){
/*tmp是a数组下标计数器,cnt = 当前数字出现次数*/
int sum = 0,a[50000],tmp = 0,cnt = 1;
bool cut = 0;
int x;
while (1){
cin >> x;
if (x == '\0') break;
sum++;
if (x == cut){
cnt++;
continue;
}
a[tmp] = cnt;
tmp++;
cnt = 1;
cut = !cut;
}
cout << sqrt(sum) << ' ';
for (int i = 0; i <= tmp-1; i++){
cout << a[i] << ' ';
}
return 0;
}
by CheeseFunction @ 2024-08-01 08:06:25
我微调了一下,就AC了:
#include <bits/stdc++.h>
using namespace std;
int main(){
/*tmp是a数组下标计数器,cnt = 当前数字出现次数*/
int sum = 0,a[50000],tmp = 0,cnt = 0;
bool cut = 0;
char x;
while (cin >> x && x != EOF){
sum++;
if (x-'0' == cut){
cnt++;
continue;
}
tmp++;
a[tmp] = cnt;
cnt = 1;
cut = !cut;
}
cout <<sqrt(sum)<< ' ';
for (int i = 1; i <= tmp; i++){
cout << a[i] << ' ';
}
cout<<cnt;
return 0;
}
by xiao_liran @ 2024-08-01 08:48:13
x是int 类型 为什么和/n进行比较(应该是这样
by CheeseFunction @ 2024-08-01 10:22:48
他关键还少了一个输出,我改了近半个小时
by hsy0824 @ 2024-08-05 21:42:18
@FearlessWarriors 谢谢