Encoding
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 26148 accepted submission (s): 11511
Problem descriptiongiven a string containing only 'a'-'Z', We cocould encode it using the following method:
1. Each sub-string containing K same characters shoshould 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
2ABCABBCCC
Sample output
ABCA2B3C
This question is strange.
# Include <stdio. h> # include <string. h> char a [11000]; int main () {int N, I, J, K; scanf ("% d", & N); While (n --) {scanf ("% s", a); for (I = 0; A [I]! = '\ 0'; I ++) {for (j = I, K = 0; j <strlen (a); k ++, J ++) {if (a [I]! = A [J]) break;} If (k> 1) printf ("% d", k); printf ("% C", a [I]); I = J-1; // limit I to the position of J in the second for loop} printf ("\ n");} return 0 ;}