HDU - 1020
2017-05-30 17:29
183 查看
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.
InputThe 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.
OutputFor each test case, output the encoded string in a line.
Sample Input
Sample Output
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.
InputThe 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.
OutputFor each test case, output the encoded string in a line.
Sample Input
2 ABC ABBCCC
Sample Output
ABC A2B3C
#include<iostream> #include<cstdio> using namespace std; int main() { char ch; int T; cin >> T; getchar(); while(T--) { int f[1050] = {1}, index = 0; char c[1050]; c[0] = getchar(); char initial = c[0]; while((ch = getchar()) != '\n') { if(initial == ch) { ++f[index]; } else { ++index; initial = ch; c[index] = ch; f[index] = 1; } } for(int i = 0; i <= index; ++i) { if(f[i] > 1) cout << f[i]; cout << c[i]; } cout << endl; } }
相关文章推荐
- hdu 1020 Encoding
- 【HDU 1020】Encoding 水
- ACM_HDU 1020 Encoding
- hdu 1020 Encoding
- HDU 1020 Encoding
- HDU 1020 Encoding 字符统计
- HDU-1020
- hdu1020--Encoding
- hdu 1020 Encoding
- hdu 1020 Encoding
- http://acm.hdu.edu.cn/showproblem.php?pid=1020..
- 【HDU】(字符串)1020_Encoding C++解法
- HDU 1020 Train Problem I 栈和队列的应用
- HDU1020 - Encoding (模拟)
- HDU-1020-Encoding(水题,但题目意思容易搞错,英语的问题)
- HDU 1020 Encoding 控制字符串的输出
- hdu_1020_Encoding(模拟)
- hdu1020 Encoding(A2B3C)
- hdu 1020 Encoding
- HDU1020 Encoding