POJ 3488 & HDU 1915 Arne Saknussemm(模拟)
2014-10-26 18:24
465 查看
题目链接:
POJ:http://poj.org/problem?id=3488
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1915
Description
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, wherelength(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 19columns 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
Source
Southeastern Europe 2007
题意:
把‘_’当作空格,'\\'当作'\n',从最后由下到上输出即可!
PS:
最后还有空格是不能输出的!
代码如下:
POJ:http://poj.org/problem?id=3488
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1915
Description
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. |
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 |
_ | 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
Source
Southeastern Europe 2007
题意:
把‘_’当作空格,'\\'当作'\n',从最后由下到上输出即可!
PS:
最后还有空格是不能输出的!
代码如下:
#include<stdio.h> #include<string.h> char p[1017][1017]; int vis[1017][1017]; int main() { int k; while(scanf("%d",&k)!=EOF) { for(int i = 0; i < k; i++) scanf("%s",p[i]); int len = strlen(p[0]); int flag = 0; memset(vis,0,sizeof vis); for(int i = 0; i < len; i++) { for(int j = 0; j < k; j++) { if(p[j][i]=='_') vis[j][i] = 1; else { flag = 1; break; } } if(flag) break; } for(int i = len-1; i >= 0; i--) { for(int j = k-1; j >= 0; j--) { if(vis[j][i]) continue; if(p[j][i]=='_') printf(" "); else if(p[j][i]=='\\') printf("\n"); else printf("%c",p[j][i]); } } printf("\n\n"); } return 0; }
相关文章推荐
- POJ 3488 & HDU 1915 Arne Saknussemm(模拟)
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
- HDU 1361 & POJ 1068 Parencodings(模拟)
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
- POJ 3923 & HDU 2487 Ugly Windows(模拟)
- poj 1019 Number Sequence && hdu 1597 find the nth digit(二分,模拟)
- POJ 3505 && HDU 2341 Tower Parking(简单模拟)
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- POJ 3650 & ZJU 2932 & HDU 2719 The Seven Percent Solution(模拟)
- HDU 1035 && poj 1573 Robot Motion【模拟】
- 【POJ】1573 & 【HDU】1035 - Robot Motion(模拟)
- poj 1218&&hdu 1337 The Drunk Jailer【简单模拟】
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
- POJ 1573 && hdu 1035 Robot Motion(简单模拟)
- POJ 1573 && hdu 1035(简单模拟)
- NYOJ 524 & HDU 2054 A==B?(模拟)
- 【扫描线法】&& poj 1177 && hdu 1828
- poj 1001 && hdu 1063 (java版本)