EncodingTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 31603 Accepted Submission (s): 14020
Problem Descriptiongiven A string containing only ' a '-' Z ', we could encode it using the following method:
1. Each sub-string containing k same characters should being encoded to "KX" where "X" was the only character in this Sub-stri Ng.
2. If the length of the sub-string is 1, ' 1 ' should are ignored.
Inputthe first line contains an integer n (1 <= N <=) which indicates the number of test cases. The next n lines contain n strings. Each string consists of only ' A '-' Z ' and the length are less than 10000.
Outputfor each test case, output the encoded string.
Sample Input
2ABCABBCCC
Sample Output
abca2b3c
Authorzhang Zheng
recommendjgshining | We have carefully selected several similar problems for you:1019 1021 1062 1032 1018
Very simple water problem, I will not tell you I am bored to cut water problem! The main meaning of the topic is: let you ask for a string inside a continuous number of different characters, attention is a continuous character! So the result of Aabcca is 2AB2CA and not 3ab2c! only this one pit point, the other no ... Also note that if the character is 1 front does not output 1 ...
Import Java.io.*;import java.util.*;p ublic class main{public static void Main (string[] args) {//TODO auto-generated Metho D stubscanner input = new Scanner (system.in), int a[] = new Int[10005];int n = input.nextint (); Input.nextline (); for (int i = 0; I < n; i++) {int count = 1; String str = Input.nextline (), char c[] = Str.tochararray (); for (int j = 1; j < C.length; J + +) {if (c[j] = = C[j-1]) {++c Ount;} Else{if (count = = 1) {System.out.print (c[j-1]);} else{system.out.print (Count + "+ c[j-1]); count = 1;}} if (j = = c.length-1) {if (count = = 1) {System.out.print (c[j]);} else{system.out.print (Count + "+ c[j]); count = 1;}}} System.out.println ();}}}
Hdu-1020-encoding (Java && Weak water 3,000)