hdoj 1020 Encoding
来源:互联网 发布:因笑谓迈曰 汝识之乎 编辑:程序博客网 时间:2024/05/29 09:15
要注意没有说要输出某字符总的个数;
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.
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
2ABCABBCCC
Sample Output
ABCA2B3C
#include<stdio.h>#include<string.h>char s[10001];int main(){int t, c;scanf( "%d", &t );getchar();while( t -- ){scanf( "%s", s );int l = strlen(s);c = 1;for( int i = 1; i < l; i ++ ){if( s[i]==s[i-1] ) ++c;else{if(c>1)printf( "%d", c );printf( "%c", s[i-1] );c = 1;}}if( s[l-1] == s[l-2] )printf( "%d%c", c, s[l-2] );elseprintf( "%c", s[l-1] );printf( "\n" );} }
0 0
- HDOJ 1020 Encoding
- hdoj 1020 Encoding
- hdoj 1020 Encoding
- HDOJ 1020 ENcoding
- hdoj 1020 encoding
- HDOJ 1020 Encoding
- HDOJ 1020 Encoding
- HDOJ 1020 Encoding
- hdoj-1020-Encoding
- HDOJ 1020 Encoding
- [HDOJ 1020]Encoding 字符串编码
- [HDOJ 1020]Encoding 字符串编码
- hdoj 1020 Encoding (水题)
- HDOJ Encoding
- HDOJ Encoding
- ACM--字母序列--HDOJ 1020--Encoding--字符串
- HDOJ 1012 Encoding
- HDOJ 1020 Encoding
- 获取请求头杂七杂八的信息
- JavaSE(5):java多线程技术
- 关于64位系统安装ia32-libs
- hdu 1228 A+B【字符串处理】
- hdu1002 a+bII 大数相加
- hdoj 1020 Encoding
- hdoj 1018 Big Number
- hdoj 1276士兵队列训练问题 【开灯类型】
- hdoj 2018 母牛的故事 【找规律】
- hdoj 1177 "Accepted today?"
- hdoj 1872 稳定排序 【冒泡】
- 感悟
- chansons jamais aimé
- c编程基础