Hdu-1020-encoding (Java && Weak water 3,000)

Source: Internet
Author: User

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)

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.