wuxinji @ 2022-11-14 19:05:47
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string s,sb;
int n = 0;
while(getline(cin,sb)){
s+=sb; //合并成一个字符串
n++; //计数,求N
}
cout << n << ' ';
int a = s[0],count = 0;
for(auto i : s){
if(i == a){
count ++;
}else if(i != a){
cout << count << ' ';
a = i;
count = 1;
}
}
cout << count ;
}
by Fatin @ 2022-12-18 10:23:38
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string s,sb;
int n = 0;
while(cin >> sb){
s+=sb; //合并成一个字符串
n++; //计数,求N
}
cout << n << ' ';
char a = '0';
int count = 0;
for(auto i : s){
if(i == a){
count ++;
}else{
cout << count << ' ';
a = i;
count = 1;
}
}
cout << count;
return 0;
}