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. 48.EXt.Data.JsonReader()

    转自:https://blog.csdn.net/huoyanxueren/article/details/2662915?utm_source=blogxgwz6 extJs 2.1学习笔记(Ext ...

  2. PCB genesis自制孔点 Font字体实现方法

    一.先看genesis原有Font字体 在PCB工程CAM加孔点字体要求时,通常我们直接用Geneis软件给我们提供了2种孔点字体canned_57与canned_67,但此字体可能不能满足各个工厂个 ...

  3. PCB ODB++(Gerber)图形绘制实现方法

    这里讲解一下用net解析PCB图形绘制实现方法 一.解析PCB图形绘制实现 解析PCB图形,说简单也非常简单,先说一下,PCB Gerber图形由:点,线,弧,铜皮,文字 5类元素组成,通常简写为:P ...

  4. cookie封装函数(添加,获取,删除)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  5. 一个不错的jquery插件模版

    pageplugin.js (function ($) { $.PagePlugin = function (obj, opt) { var options = $.extend({}, $.Page ...

  6. jdk11安装没有jre文件夹

    原因:jdk11安装之后是没有jre的 如果需要jre,需要到jdk目录下面去    打开命令窗口,然后执行如下命令:    bin\jlink.exe --module-path jmods --a ...

  7. Android项目实战_手机安全卫士软件管家

    ###1.应用程序信息的flags 1. int flags = packageInfo.applicationInfo.flags2. 0000 0000 0000 0000 0000 0000 0 ...

  8. python 求一个文件中每个字符出现的次数

    import pprint import collections filename = input('Input filename') with open(filename) as info: cou ...

  9. Java我来了

    七天的C#集训,第一天接触Java,觉得很多相似的地方,尝试用eclipse码了几句(有些差别,毕竟没有写C#那么流畅),总体来说觉得还不错,对自己接下来要求是,更加熟练并且牢记Java的命令,更加深 ...

  10. Caffe2:添加CUDA路径

    在使用Eclipse时候,仍然出现 libcuda.so 找不到的情况..... 原因:cuda环境没有设置到系统环境中. 方案: 设置CUDA path: 在bashrc中添加路径,只对当前用户产生 ...