Fork me on GitHub

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

【题目链接:HDOJ-1020

  相邻字符,两两比较。

 1 #include<cstdio>
 2 #include<cstring>
 3 const int MAXN = 10002;
 4 char sr[MAXN];
 5 int main(){
 6     int n;
 7     scanf("%d",&n);
 8     while(n--){
 9         scanf("%s",sr);
10         int num = 1,i;
11         for(i = 0;i < strlen(sr);i++){
12             if(sr[i] == sr[i+1]){
13                 num++;
14             }else{
15                 if(num <= 1)
16                     printf("%c",sr[i]),num = 1;
17                 else{
18                     printf("%d%c",num,sr[i]),num = 1;
19                 }                    
20             }
21         }
22         printf("\n");
23     }
24     return 0;
25 } 

 

posted @ 2015-05-06 23:54  郑斌blog  阅读(249)  评论(0编辑  收藏  举报