MaxLKY @ 2024-03-24 10:05:10
#include<bits/stdc++.h>
using namespace std;
int main(){
strin a="",b;
while(cin>>b){
a=a+b;
}
int cnt=0;
cout<<sqrt(a.size())<<" ";
/*for(int i=1;i<=a.size();i++){
if(a[i]=='0'){
cnt++;
}else{
cout<<cnt<<" ";
cnt=0;
}
}*/
return 0;
}
注释段怎吗写? 求助!!!
by chenbingjie @ 2024-03-30 11:43:15
@MaxLKY cnt=1;
by canwen @ 2024-04-05 15:16:19
我写的AC了嘻嘻 我的思路先读取一行代码 统计n,然后循环读取,模拟即可
#include<iostream>
#include<cstring>
using namespace std;
char shuzu[200];int ans[201*201];
int main(){
int flag=0;//flag=0,统计0;等于1,统计1
cin>>shuzu;int num=0,j=0;
int n=strlen(shuzu);
for(int i=0;i<n;i++){
if(flag==0) {
if(shuzu[i]=='0') {
num++;
}else{
ans[++j]=num;
//cout<<flag<<"的统计截止:"<<ans[j]<<endl;
num=1;
flag=1;
}
}else{
if(flag==1){
if(shuzu[i]=='1') {
num++;
}else{
ans[++j]=num;
//cout<<flag<<"的统计截止:"<<ans[j]<<endl;
num=1;
flag=0;
}
}
}
}
for(int i=2;i<=n;i++){
cin>>shuzu;
for(int i=0;i<n;i++){
if(flag==0) {
if(shuzu[i]=='0') {
num++;
}else{
ans[++j]=num;
//cout<<flag<<"的统计截止:"<<ans[j]<<endl;
num=1;
flag=1;
}
}else{
if(flag==1){
if(shuzu[i]=='1') {
num++;
}else{
ans[++j]=num;
//cout<<flag<<"的统计截止:"<<ans[j]<<endl;
num=1;
flag=0;
}
}
}
}
}
cout<<n<<" ";
for(int i=1;i<=j;i++){
cout<<ans[i]<<" ";
}
cout<<num;
}
by MaxLKY @ 2024-04-26 22:40:42
栓Q啊