首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >杭电1020

杭电1020

作者头像
用户1749219
发布2018-05-16 10:49:22
6920
发布2018-05-16 10:49:22
举报

Problem Description

Given a string containing only 'A' - 'Z', we could encode it using the following method:  1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string. 2. If the length of the sub-string is 1, '1' should be ignored.

Input

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.

Output

For each test case, output the encoded string in a line.

Sample Input

2 ABC ABBCCC

Sample Output

ABC A2B3C

水题,一开始误解了意思,以为是求一串字符串中相同字母的个数并输出,其实是求连续字母的个数并输出。

代码如下:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define max 10001
 4 int main(){
 5     int n=0;
 6     scanf("%d",&n);
 7     while(n--){
 8         char s[max];
 9         scanf("%s",s);
10         int count=1,
11             i;
12         for(i=0;i<strlen(s);i++){
13             if(s[i]==s[i+1])count++;
14             else{
15                 if(count==1)printf("%c",s[i]);
16                     else printf("%d%c",count,s[i]);
17                     count=1;
18             }
19         }
20         printf("\n");
21     }
22     return 0;
23 
24 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-01-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档