yyao433100 @ 2024-04-06 01:11:03
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string str;
getline(cin, str);
int n = str.length();
vector<int> myvector;
// cout << n << " ";
myvector.push_back(n);
int count = 0;
char w = str[0]; // 标识0或1;
for (int j = 0; j < n; j++)
{
if (str[j] == w)
{
count++;
}
else
{
myvector.push_back(count);
// cout << count << endl;
count = 1;
w = str[j];
}
}
for (int i = 0; i < n - 1; i++)
{
// cin >> str;
getline(cin, str);
// cout << str << endl;
for (int j = 0; j < n; j++)
{
if (str[j] == w)
{
count++;
}
else
{
myvector.push_back(count);
// cout << count << endl;
count = 1;
w = str[j];
}
}
}
// if (str[n - 2] == str[n - 1])
myvector.push_back(count);
for (vector<int>::iterator it = myvector.begin(); it != myvector.end(); it++)
{
cout << *it << " ";
}
}
by m1xax @ 2024-04-07 17:31:01
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s,k;
ll n,a=1;
int main(){
cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
while(cin>>k){
s+=k;
}s+='k';
n=k.size();
cout<<n<<" ";
if(s[0]=='1'){
cout<<"0 ";
}
for(int i=1;i<s.size();i++){
if(s[i]==s[i-1]){
a++;
}else{
cout<<a<<" ";
a=1;
}
}
return 0;
}