Hdu-1200-to and Fro (Java Farmer Spring + simple Simulation)

Source: Internet
Author: User

To and FroTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5161 Accepted Submission (s): 3573


Problem Descriptionmo and Larry have devised a by encrypting messages. They first decide secretly on the number of columns and write the message (Letters only) down the columns, padding with ex TRA random letters so as to make a rectangular array of letters. For example, if the message is "there's no place like home on a snowy night" and there be five columns, Mo would write do Wn

t o i o y
H p k N N
E l e a I
R a h S G
E c o n H
S e m o T
N l e W x


Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character ' X ' to pad the message out to make a rectangle, although he could has used any let ter.

Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would is encrypted as

Toioynnkpheleaigshareconhtomesnlewx

Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.

Inputthere'll be multiple input sets. Input for each set would consist of the lines. The first line would contain an integer in the range 2. . . indicating the number of columns used. The next line was a string of up to $ lower case letters. The last input set was followed by a line containing a single 0, indicating end of input.

Outputeach input set should generate one line of output, giving the original plaintext message, with no spaces.

Sample Input
5toioynnkpheleaigshareconhtomesnlewx3ttyohhieneesiaabss0

Sample Output
Theresnoplacelikehomeonasnowynightxthisistheeasyoneab

Sourceeast Central North America 2004
RECOMMENDIGNATIUS.L | We have carefully selected several similar problems for you:1196 1073 1161 1039 1020
This is fruit compared to dynamic planning. Because there is no turning and no pit, straight to the line. First, a two-dimensional array is stored in this form. This is stored in odd rows from left to right, even from right to left, which should be well understood and can be done with a single judgment statement.


Then follow the top to bottom, that is, the outer loop control the number of columns, the inner loop control the number of rows output is OK!



Import Java.io.*;import java.util.*;p ublic class main{public static void Main (string[] args) {Scanner input = new Scanner (S ystem.in); while (Input.hasnext ()) {int n = input.nextint (); if (n==0) break;input.nextline (); String str = Input.nextline (); char c1[] = Str.tochararray ();                   Save each character as a single char c2[][] = new Char[1010][1010];int line = c1.length/n;                        Record number of rows int k = 0;                                      Record the number of digits for the C1 character for (int i = 0, i < line; i++) {if (i% 2 = = 1) {for (int j = n-1; J >= 0; j--) {c2[i][j] = c1[k++];} el se{for (int j = 0; J < N; j + +) {C2[i][j] = c1[k++];}} for (int j = 0; J < N; j + +) {for (int i = 0; i < line; i++) {System.out.print (c2[i][j]);}} System.out.println ();}}}



Hdu-1200-to and Fro (Java Farmer Spring + simple Simulation)

Related Article

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.