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. PCB SQL Server 触发器应用实例

    这里以实际例子对触发器的应用对触发器的理解与应用来得更实际 一.更新触发器(Update) 临时表:inserted表有数据(新数据)     Deleted表有数据(旧数据) 实例说明:当表更新时, ...

  2. codevs1163访问艺术馆(树形dp)

    1163 访问艺术馆  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master   题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备, ...

  3. P3194 [HNOI2008]水平可见直线

    传送门 我们把所有的直线按斜率从小到大排序,然后用单调栈维护 发现,如果当前直线与\(st[top-1]\)直线的交点的横坐标大于等于与\(st[top]\)的交点的横坐标,当前直线可以覆盖掉\(st ...

  4. POJ 1873 计算几何

    思路: 二进制枚举一下要删哪些点 求个凸包,算一下贡献 //By SiriusRen #include <cmath> #include <cstdio> #include & ...

  5. Leetcode03---Longest Substring Without Repeating Characters

    Description: Given a string, find the length of the longest substring without repeating characters. ...

  6. 前端h5开发调试神奇vconsole

    (1)项目中安装vconcole插件 npm install vconcole (2)在vue项目中main.js中引入插件 import Vconsole from 'vconsole'; cons ...

  7. 02--Tomcat总体结构分析一

    注:此文章大部分参考大神文档,并且结合自身理解,补充了其他相关知识,谢绝转载.      大神原文地址链接:http://www.ibm.com/developerworks/cn/java/j-lo ...

  8. Less——less基本安装

    1.下载node.js 我们需要NodeJ运行LESS示例. 要下载NodeJ,请打开链接https://nodejs.org/en/ 2.node.js安装是否正确 在cmd中输入lessc -v, ...

  9. jQuery——属相操作

    属性获取:attr(属性名), 属性设置:attr(属性名,具体值) 移除属性:removeAttr(属性名) 特殊情况:prop(属性名).prop(属性名,具体值):表单中状态属性checked. ...

  10. vim之补全1(完全个人定制版)

    关于vim的补全最初的感觉是蛋疼, 真正的蛋疼! 由于在接触linux之前曾经在windows下面学过一段时间软件开发, 那时使用的是vs2010, 现在看来虽然vs启动相当的慢, 编辑器的定制和配置 ...