Noah_Shen @ 2024-08-28 18:37:12
#include <bits/stdc++.h>
using namespace std;
int a[40001],cnt,temp;
int main(){
char c;
while(cin >> c){
a[++cnt] = c - '0';
}
int d = a[1];
int n = sqrt(cnt);
cout << n << " ";
for(int i = 1; i <= cnt; i++){
if(a[i] == d){
temp++;
}else{
cout << temp << " ";
d = !d;
temp = 1;
}
if(i == cnt){
cout << temp;
}
}
return 0;
}
by CQ天神 @ 2024-08-28 18:39:24
@Noah_Shen 我的代码,你先参考一下,我马上帮你看一下:
#include<bits/stdc++.h>
using namespace std;
int a;
string s,t="0";
int main(){
while(getline(cin,s)) t+=s;
cout<<sqrt(t.size()-1);
for(int i=1;i<t.size();i++){
if(t[i]!=t[i-1]){
cout<<' '<<a;
a=0;
}
a++;
}
cout<<' '<<a;
return 0;
}
by Noah_Shen @ 2024-08-28 18:57:25
@CQ天神 谢谢大佬,求互关
by CQ天神 @ 2024-08-28 18:59:51
@Noah_Shen done.