Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22110    Accepted Submission(s): 9687

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
 #include <stdio.h>
#include <string.h> char str[]; int main()
{
int cases;
scanf("%d",&cases);
getchar();
while(cases--)
{
int i,len,count=;
char c;
scanf("%s",str);
len=strlen(str);
i=;c=str[i];
while(i<len)
{
while(str[i+] == c)
{
count++;
i++;
}
if(count)
{
printf("%d%c",count+,c);
count = ;
c = str[i+];
}
else
{
printf("%c",c);
count = ;
c = str[i+];
}
i++;
}
printf("\n");
}
return ;
}

做过,水过!

 

hdu_1020_Encoding_201310172120的更多相关文章

随机推荐

  1. js addeventlistener 刮刮贴

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...

  2. The Preliminary Contest for ICPC China Nanchang National Invitational I.Max answer单调栈

    题面 题意:一个5e5的数组,定义一个区间的值为 这个区间的和*这个区间的最小值,注意数组值有负数有正数,求所有区间中最大的值 题解:如果全是正数,那就是原题 POJ2796 单调栈做一下就ok 我们 ...

  3. [Swift通天遁地]三、手势与图表-(5)创建带有标题、图例、坐标轴的柱形图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. [Swift通天遁地]七、数据与安全-(20)快速实现MD5/Poly1305/Aes/BlowFish/Chacha/Rabbit

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. 慕课网3-13编程练习:采用flex弹性布局制作页面主导航

    小伙伴们,伸缩容器的属性我们已经学完了,接下来使用我们所学的伸缩容器属性完成下面的效果图. 要求: 1.logo.导航项.登录注册按钮这三项在水平和垂直方向上都对齐,而且他们之间的距离也相等. 2.导 ...

  6. IOC框架---什么是IOC

    1 IoC理论的背景    我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑.                    ...

  7. “国家队爷”杯液体战争AI比赛!!__SymenYang

    原帖 这两天一直在搞这个AI,提供的样例更本不是我的风格啊,看不懂更不会改... 所以我自己写了一个AI的平台,现在在不断的修改AI的策略,smart样例还是很容易过的,让line的行走速度变慢一点到 ...

  8. UNIX环境高级编程--4

    函数stat fstat fstatat 和 lstat stat函数使用最多的地方可能就是ls -l 命令,用其可以获得有关一个文件的所有信息. 文件类型: (1)普通文件 (2)目录文件 (3)块 ...

  9. jQuery :even

    此选择器匹配所有索引值为偶数的元素,从0开始计数. jQuery1.0版本添加. 语法结构: jQuery( ":even" ) 代码实例: <!doctype html&g ...

  10. 淘宝ip地址库接口会导致TTFB时间变长,网站打开速度变慢

    前一段时间闲来无事发现别人的网站上有显示当前用户城市的功能,就自己也整了一个 这是淘宝ip地址库调用方法 然后问题就出现了,网站打开速度慢的要死 用F12发现是TTFB太慢,然后百度了,发现了问题的原 ...