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 ;
}

HDU 1020.Encoding-字符压缩的更多相关文章

  1. HDU 1020 Encoding POJ 3438 Look and Say

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. HDU 1020 Encoding 模拟

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. HDU 1020 Encoding【连续的计数器重置】

    Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. hdu 1020 Encoding

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Given a ...

  5. HDU 1020:Encoding

    pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  6. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  7. hdu 5724 SG+状态压缩

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  8. HDU 1020(连续同字符统计 **)

    题意是要统计在一段字符串中连续相同的字符,不用再排序,相等但不连续的字符要分开输出,不用合在一起,之前用了桶排序的方法一直 wa,想复杂了. 代码如下: #include <bits/stdc+ ...

  9. hdu 4272 LianLianKan 状态压缩

      LianLianKan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. Visual Studio调试之断点技巧篇

    原文链接地址:http://blog.csdn.net/Donjuan/article/details/4618717 函数断点 在前面的文章Visual Studio调试之避免单步跟踪调试模式里面我 ...

  2. BZOJ1202:狡猾的商人(带权并查集)

    1202: [HNOI2005]狡猾的商人 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1202 Description: 刁姹接到一个 ...

  3. codeforces 799C Fountains

    C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  4. bzoj 1110 [POI2007]砝码Odw 贪心+进制转化

    [POI2007]砝码Odw Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 661  Solved: 366[Submit][Status][Disc ...

  5. js和jquery修改背景颜色的区别

    html: <HTML> <head> <meta http-equiv="content-type" content="text/html ...

  6. shell编程 if 注意事项

    read -n 1 -p "Let's go(y or n):" if [ "$REPLY"x = "y"x -o "$REPLY ...

  7. JavaScript学习笔记——浅拷贝、深拷贝

    参考自:http://www.cnblogs.com/yichengbo/archive/2014/07/10/3835882.html 一.数组的深浅拷贝 在使用JavaScript对数组进行操作的 ...

  8. Spring - IoC(12): 属性占位符

    使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...

  9. Gradle体验/第一篇:下装、安装、配置、体验

    http://jingyan.baidu.com/article/4d58d541167bc69dd4e9c009.html

  10. 【uva11732-"strcmp()" Anyone?】Trie

    http://acm.hust.edu.cn/vjudge/problem/28438 题意:给定n个字符串,问用strcmp函数比较这些字符串共用多少次比较. 题解: 插入一个‘#’作为字符串的结束 ...