HDU 1020 Encoding

Source: Internet
Author: User

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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.