Encoding

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

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>
int main(){
char str[];
int n,i,cnt;
while(~scanf("%d",&n)){
while(n--){
scanf("%s",&str);
for(i=;str[i]!='\0';i++){
cnt=;
while(str[i]==str[i+]){
cnt++;i++;
}
if(cnt==) printf("%c",str[i]);
else printf("%d%c",cnt,str[i]);
}
printf("\n");
}
}
return ;
}

最新文章

  1. PHP 如何获取当前的域名
  2. Atitit RSA非对称加密原理与解决方案
  3. uploadfile上传文件时ie浏览器无法弹出窗口
  4. head first c&amp;lt;11&amp;gt;初探网络编程上
  5. [译]JavaScript 错误和处理
  6. javascript 的点击复制事件
  7. python文本文件,生成指定的文件格式
  8. MySQL索引的使用方式
  9. oracle查询用户权限及角色(摘)
  10. [Flask]学习杂记--模板
  11. 记账本-NABCD分析
  12. 【工具】idea工具 java代码 gbk转utf8
  13. CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-6CM安装前环境检查
  14. VS Code 编辑器
  15. MySQL基础知识——范式与事务
  16. android 退出程序解决内存释放so的问题
  17. express4.x Request对象获得参数方法小谈【原创】
  18. python列表解析进阶
  19. Session和Cookie详解(1)
  20. bzoj 4004 [JLOI2015]装备购买 拟阵+线性基

热门文章

  1. [剑指Offer] 7.斐波那契数列
  2. Hibernate关联映射之_多对一
  3. BZOJ 1040: [ZJOI2008]骑士 | 在基环外向树上DP
  4. [LeetCode] decode ways 解码方式
  5. Angular 遍历循环数组
  6. 如何加快JavaScript的加载与执行
  7. 2017年研究生数学建模D题(前景目标检测)相关论文与实验结果
  8. bzoj 4879 失控的数位板 4881 线段游戏 贪心,瞎搞
  9. java 构造函数问题
  10. Android百度定位地图使用--文章集锦