fanhy @ 2017-10-22 12:18:43
#include<iostream>
#include<string>
using namespace std;
int sum;
char bo;
int main()
{
string s;
cin>>s;
bo=s[0];
int n=s.length();
string str;
str+=s;
for(int i=1;i<n;i++)
{
cin>>s;
str+=s;
}
cout<<n;
for(int i=0;i<n*n;i++)
{
if(str[i]==bo) sum++;
else
{
cout<<' '<<sum;
sum=1;
if(bo=='0') bo='1';
else if(bo=='1') bo='0';
}
}
return 0;
}
by hongzy @ 2017-12-08 21:38:18
bo初始是‘0’,还有最后要输出sum
#include<iostream>
#include<string>
using namespace std;
int sum;
char bo;
int main() {
string s;
cin>>s;
bo='0';
int n=s.length();
string str(s);
for(int i=1; i<n; i++) {
cin>>s;
str+=s;
}
cout<<n;
for(int i=0; i<n*n; i++) {
if(str[i]==bo) sum++;
else {
cout<<' '<<sum;
sum=1;
if(bo=='0') bo='1';
else if(bo=='1') bo='0';
}
}
cout<<' '<<sum<<endl;
return 0;
}