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>
int main()
{
int N, length, count;
char str[10001];
scanf("%d", &N);
while (N)
{
scanf("%s", str);
length = strlen(str);
count = 1;
for (int i = 1; i <= length; i++)
{
if (str[i] == str[i - 1])
count++;
else
{
if (count == 1)
printf("%c", str[i - 1]);
else
{
printf("%d%c", count, str[i - 1]);
count = 1;
}
}
}
printf("\n");
N--;
}
return 0;
}

  

最新文章

  1. [vijos P1083] 小白逛公园
  2. tz2txt的安装与使用
  3. 每天一个linux命令(41):at命令
  4. ECshop 每个数据库表结构说明
  5. Ununtu 12.04 gedit安装插件Source Code Browser
  6. JQUERY选择和操作DOM元素(利用正则表达式的方法匹配字符串中的一部分)
  7. 初识golang
  8. R系列:分词、去停用词、画词云(词云形状可自定义)
  9. HTML DOM应用案例2
  10. (关于数据传输安全)SSH协议
  11. Jmeter之Constant Timer与constant throughput timer的区别(转)
  12. NEST - 编写查询
  13. 清除 System.Web.Caching.Cache 以&quot;xxx&quot;开头的缓存
  14. 【转】web应用缓慢故障分析
  15. linux系统下添加新硬盘的方法详解
  16. 关《我是IT小小鸟》有感
  17. UNIX网络编程读书笔记:TCP输出、UDP输出和SCTP输出
  18. JavaScript indexof方法
  19. 【OBJC】数字转中文大写
  20. bzoj3502[PA2012]Tanie Linie(最大k区间和)

热门文章

  1. 【转】15个必须知道的chrome开发者技巧
  2. Sqoop操作集合
  3. ASP.NET Core 编码、web编码、网页编码 System.Text.Encodings.Web
  4. Android studio ocr初级app开发问题汇总(含工程代码)
  5. 【Alpha】总结 - (待更)
  6. Linux和Unix的区别
  7. background-clip 实现字体渐变效果
  8. .Net Sokcet 异步编程
  9. nginx判断为404跳转
  10. yum 安装 php5.6