输入输出 + 字符串操作
2023-08-15 14:41:21
发布于:上海
3阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main(){
char k[10001];
cin>>k;
for(int i=0;i<strlen(k);i++){
if(k[i]>='a' and k[i]<='z'){
k[i]=k[i]-'a'+'A';
}
}
char cnt;
cnt=k[0];
cout<<"(";
int num=0;
for(int i=0;i<strlen(k);i++){
if(i==strlen(k)-1 and k[i]==cnt){
cout<<cnt<<","<<num+1<<")";
break;
}
else if(i==strlen(k)-1 and k[i]!=cnt){
cout<<cnt<<","<<num<<")(";
cout<<k[i]<<","<<1<<")";
continue;
}
if(int(k[i])!=int(cnt)){
cout<<cnt<<","<<num<<")(";
num=1;
cnt=k[i];
continue;
}
if(k[i]==cnt) num++;
}
return 0;
}
这里空空如也
有帮助,赞一个