HDU 1915 Arne Saknussemm

Source: Internet
Author: User

 

Arne Saknussemm

Time Limit: 5000/1000 MS (Java/others) memory limit: 65535/32768 K (Java/Others)
Total submission (s): 216 accepted submission (s): 63


Problem descriptionfollowing
The account of Jules Verne, a scrambled message written by the middle
Age alchemist Arne Saknussemm, and deciphered by using sor lidenbrock,
Started the incredible travel to the center of the earth.
Scrambling procedure used by Arne is alike the procedure given below.

1.
Take a non empty message m that contains letters from the English
Alphabet, digits, commas, dots, quotes (I. e. '), spaces and line
Breaks, and whose last character is different than space. For example,
Consider the following message whose Translation reads "in Sneffels's
Crater descend Brave traveler, and touch the Center of the Earth ".

In Sneffels craterem descende audasviator, et Terrestre centrum attinges.

2.
Choose an integral number 0 <k ≤ length (M) and add trailing spaces to m
Such that the length of the resulting message, say m', is the least
Multiple of K. For k = 19 and the message above, where length (m) = 74
(Including the 8 spaces and the line break that M contains), two
Trailing spaces are added yielding the message m' with length (m') = 76.

3.
Replace all the spaces from m' by the character _ (underscore );
Replace all the line breaks from m' by/(backslash), and then reverse
The message. In our case:

_. Segnitta_murtnec_ertserret_te _, rotaiv/sadua_ednecsed_meretarc_sleffens_ni

4.
Write the message that results from step 3 in a table with length (m')/K
Rows and K columns. The writing is column wise. For the given example,
The message is written in a table with 76/19 = 4 rows and 19 columns
Follows:
[Image missing]

5. the strings of characters that correspond
To the rows of the table are the fragments of the scrambled message.
The 4 Fragments of Arne's message given in step 1 are:

_ Etmneet_t/udsmt_fs.narctrtria_edrrlen
_ Gtuerr _, asaneeasf_si_t_seeovdec_eceni

Write
A program that deciphers non empty messages scrambled as described.
Length of a message, before scrambling, is at most 1000 characters,
Including spaces and line breaks.

 

 

Inputthe
Program input is from a text file where each data set corresponds to
Scrambled message. A data set starts with an integer N, that shows
Number of fragments of the scrambled message, and continues with N
Strings of characters that designate the fragments, in the order they
Appear in the table from step 4 of the scrambling procedure. Input Data
Are separated by white-spaces and terminate with an end of file.

 

 

Outputthe
Deciphered message must be printed on the standard output, from
Beginning of a line and must be followed by an empty line as shown in
The input/output sample below.

 

 

Sample Input
4  _etmneet_t/udsmt_fS   _gtuerr_,asaneeasf_   .narctrtria_edrrlen   si_t_seeovdec_ecenI11 e n r e V _ s e l u J
 

 

Sample output
In Sneffels craterem descende audasviator, et terrestre centrum attinges.
Jules Verne
 

 

Source southeastern Europe 2007

 

 

Question:

The tragic question, today I found that I have been doing nothing wrong, and there are no more outputs for spaces, but less empty rows at the end of the output. A lot of nonsense, I directly read the test data and found that there is no blank line behind the second data. The error is here. I marked it in red.

# Include <iostream> <br/> # include <string> <br/> using namespace STD; <br/> int main () <br/>{< br/> int N, I = 0, J, L, flag; string s [1000], SS; <br/> while (CIN> N) <br/> {<br/> flag = 0; <br/> SS = ""; <br/> for (I = 0; I <n; I ++) <br/> CIN> S [I]; <br/> L = s [0]. length (); <br/> for (j = 0; j <L; j ++) <br/> for (I = 0; I <n; I ++) <br/> {<br/> If (s [I] [J]! = '_') <Br/> flag = 1; <br/> If (FLAG) <br/> {<br/> If (s [I] [J] = '_') <br/> SS + = ''; <br/> else if (s [I] [J] = '//') <br/> SS + = '/N '; <br/> else <br/> SS + = s [I] [J]; <br/>}< br/> L = ss. length (); <br/> for (I = IL-1; I >=0; I --) <br/> cout <ss [I]; <br/> cout <Endl; <br/>}< br/> return 0; <br/>}< br/>

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.