hdu1020
2015-08-26 17:48
513 查看
Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33303 Accepted Submission(s): 14811
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
Author
ZHANG Zheng
#include <stdio.h> #include <string.h> main () { int n; char str[10005]; int i,j,len,t; scanf ("%d",&n); while (n--) { scanf ("%s",str); len=strlen(str); t=1; for (i=0;i<len;i++) { if (str[i]==str[i+1]) t++; if (str[i]!=str[i+1]) { if (t!=1) { printf ("%d%c",t,str[i]); t=1; } else { printf ("%c",str[i]); t=1; } } } printf ("\n"); } }
相关文章推荐
- 正则表达式全部符号解释
- BLOCK传值 协议传值
- KEIL之新版V5使用
- 论C++的静态联编和动态联编
- DuiLib属性
- css图片上文字居中,兼容微信
- Error:Android Source Generator: [sdk] Android SDK is not specified.
- 2015.8.26
- XP下Winform背景透明问题
- java校验导入的模板
- 运维屌丝回答网传Linux运维面试题(四)
- 适配iPhone6和6P UITableView分割线会闪动(拖动UITableView的时候,分割线 一会儿变粗一会儿变细)解决办法
- 字典类型的json字符串中的key要用双引号,而不能用单引号
- CSS3 选择器
- CSU 1506 酷酷的单词
- 视频、音频打时间戳的方法及其音视频同步(播放)原理
- 使用36-pin的STM32输出VGA, VGA output using a 36-pin STM32
- NSNumber简略了解
- [WPF] 为Style 里的button添加鼠标点击响应事件
- HTML5 缓存: cache manifest