zoj 3121
2009-10-05 10:22
316 查看
Arne Saknussemm
Time Limit: 1 Second Memory Limit: 32768 KB
Following the account of Jules Verne, a scrambled message written by the middle age alchemist Arne Saknussemm, and deciphered by professor Lidenbrock, started the incredible travel to the center of the Earth. The 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".
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:
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 as follows:
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:
Write a program that deciphers non empty messages scrambled as described. The length of a message, before scrambling, is at most 1000 characters, including spaces and line breaks.
Input
The program input is from a text file where each data set corresponds to a scrambled message. A data set starts with an integer n, that shows the 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.
Output
The deciphered message must be printed on the standard output, from the beginning of a line and must be followed by an empty line as shown in the input/output sample below.
Sample Input
Sample Output
Time Limit: 1 Second Memory Limit: 32768 KB
Following the account of Jules Verne, a scrambled message written by the middle age alchemist Arne Saknussemm, and deciphered by professor Lidenbrock, started the incredible travel to the center of the Earth. The 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 audas viator, et terrestre centrum attinges. |
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 |
_ | e | t | m | n | e | e | t | _ | t | / | u | d | s | m | t | _ | f | S |
_ | g | t | u | e | r | r | _ | , | a | s | a | n | e | e | a | s | f | _ |
. | n | a | r | c | t | r | t | r | i | a | _ | e | d | r | r | l | e | n |
s | i | _ | t | _ | s | e | e | o | v | d | e | c | _ | e | c | e | n | I |
_etmneet_t/udsmt_fS .narctrtria_edrrlen | _gtuerr_,asaneeasf_ si_t_seeovdec_ecenI |
Input
The program input is from a text file where each data set corresponds to a scrambled message. A data set starts with an integer n, that shows the 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.
Output
The deciphered message must be printed on the standard output, from the 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_ecenI 11 e n r e V _ s e l u J
Sample Output
In Sneffels craterem descende audas viator, et terrestre centrum attinges.
Jules Verne
老是PF很郁闷啊?谁能解释一下?
#include <iostream> #include <string> using namespace std; int main() { char a[1000][1000]; char m[1001]; int n; string str; // string r = ""; while(scanf("%d",&n)!=EOF) { int i,j,l,k=0; for(i = 0 ; i < n; i++) { cin>>str; l = str.length(); for(j = 0 ; j < l ; j++) a[i][j] = str.at(j); } for( j = 0 ; j < l; j++) { for(i = 0 ; i < n; i++) { m[k] = a[i][j]; k++; } } //printf("/n"); //r+='/n'; for( int p = k-1; p >= 0; p--) { if(m[p]=='_') { if(p>=0&&m[p-1]!='_') printf(" "); // r+=' '; } else if(m[p]=='//') printf("/n"); // r+='/n'; else printf("%c",m[p]); // r+=m[p]; } printf("/n"); if(n!=EOF) printf("/n"); else break; //r+='/n'; } //cout<<r; return 0; }
相关文章推荐
- zoj 3121 Arne Saknussemm
- ZOJ 3121 Arne Saknussemm
- ZOJ 3121 Arne Saknussemm
- ZOJ-3121
- ZOJ 3121 Arne Saknussemm
- ZOJ Problem Set - 1243 URLs
- zoj 3702 Gibonacci number
- ZOJ 3166题解 最短路径之Floyd算法
- ZOJ 2027 Traveling fee dp+floyed
- zoj 1857 || poj 2607
- ZOJ-3770(Ranking System)
- zoj 1089 lotto (DFS )
- poj 1287||zoj 1372 Networking 最小生成树 kruskal 克鲁斯卡尔算法
- zoj 2110 || hdoj 1010 Tempter of the Bone(DFS)
- 【ZOJ】1610 Count the Colors(线段树查找隔断的线段)
- zoj 1383 Binary Numbers&&zoj 1491 Climbing Worm(简单)
- zoj 3781 Paint the Grid Reloaded 最短路变形
- zoj 3305
- 【ZOJ2112】【整体二分+树状数组】带修改区间第k大
- zoj 1439