lizishi @ 2024-07-08 12:17:08
明月别枝惊鹊,清风半夜鸣蝉。
稻花香里说丰年,听取WA声一片。
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char str[200];
char ch[200][200];
char input[200];
cin >> str;
int len = strlen(str);
cout << len << ' ';
for (int i = 0; i < len; i++) {
ch[0][i] = str[i];
}
for (int i = 1; i < len; i++) {
cin >> input;
for (int j = 0; j < len; j++) {
ch[i][j] = input[j];
}
}
int cnt = 1;
int ttl = 0;
char lastch = ch[0][0];
for (int i = 0; i < len; i++) {
for (int j = 0; j < len; j++) {
if ((i == 0) && (j == 0)) continue;
if (lastch == ch[i][j]) {
cnt++;
}
else {
cout << cnt << ' ';
ttl += cnt;
cnt = 1;
}
if ((i == len - 1) && (j == len - 1)) {
cout << len * len - ttl;
}
lastch = ch[i][j];
}
}
return 0;
}
by lixianyuan @ 2024-07-10 15:07:54
#include<bits/stdc++.h>
using namespace std;
int main(){
string a[205];
char c='0';
int sum=0;
cin>>a[0];
for(int i=1;i<a[0].size();i++)cin>>a[i];
cout<<a[0].size()<<" ";
for(int i=0;i<a[0].size();i++){
for(int j=0;j<a[0].size();j++){
if(a[i][j]==c)sum++;
else{
c=a[i][j];
cout<<sum<<" ";
sum=1;
}
}
}
cout<<sum;
return 0;
}