【字符串处理】HDOJ-1020-Encoding

时间:2023-03-09 15:46:54
【字符串处理】HDOJ-1020-Encoding

【题目链接:HDOJ-1020

  相邻字符,两两比较。

 #include<cstdio>
#include<cstring>
const int MAXN = ;
char sr[MAXN];
int main(){
int n;
scanf("%d",&n);
while(n--){
scanf("%s",sr);
int num = ,i;
for(i = ;i < strlen(sr);i++){
if(sr[i] == sr[i+]){
num++;
}else{
if(num <= )
printf("%c",sr[i]),num = ;
else{
printf("%d%c",num,sr[i]),num = ;
}
}
}
printf("\n");
}
return ;
}