POJ - 3488 Arne Saknussemm(水题,细节题)
来源:互联网 发布:随意画线软件 编辑:程序博客网 时间:2024/04/29 21:47
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 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. ForK=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 as follows:
_etmneet_t\udsmt_fS_gtuerr_,asaneeasf_.narctrtria_edrrlensi_t_seeovdec_ecenI5. 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. 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
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
注意细节,结尾的空格处理,没空格的要加个空字符。
#include<iostream>#include<cstring>#include<string>#include<cstdio>#include<algorithm>using namespace std;int main(){int n;while (scanf("%d", &n)!=EOF){char s[1001][1001];for (int i = 0; i < n; i++)scanf("%s", s[i]);int len = strlen(s[0]);char ans[1001];int k = 0;for (int i = len - 1; i >= 0;i--)for (int j = n - 1; j >= 0; j--)ans[k++] = s[j][i];for (int i = 0; i < k; i++){if (ans[i] == '_') ans[i] = ' ';else if (ans[i] == '\\') ans[i] = '\n';}ans[k] = '\0';for (int i = k - 1; ans[i] == ' '; i--)ans[i] = '\0';printf("%s\n\n", ans);}return 0;}
- POJ - 3488 Arne Saknussemm(水题,细节题)
- poj 3488 Arne Saknussemm 模拟题
- POJ 3488 Arne Saknussemm 可能会
- POJ 3488 & HDU 1915 Arne Saknussemm(模拟)
- POJ 3488 Arne Saknussemm 字符串译码
- Arne Saknussemm
- Arne Saknussemm
- HDU 1915 Arne Saknussemm (解题报告)
- zoj3121 Arne Saknussemm(题目没看完,感觉可能是阅读理解题,待ac吧)
- HDU 1915 Arne Saknussemm
- HDU 1915 Arne Saknussemm
- ZOJ 3121 Arne Saknussemm
- zoj 3121 Arne Saknussemm
- ZOJ3121 POJ3488 Arne Saknussemm
- ZOJ 3121 Arne Saknussemm
- ZOJ 3121 Arne Saknussemm
- ZCMU-1403-Arne Saknussemm
- POJ 1278(细节prim)
- 小马哥---高仿红米MI NOTE 小米5 实战详细拆机主板图与开机界面图 H78主板 高仿小米15年新版
- (4.4.3)android的布局类
- Java中的instanceof关键字
- c语言关于字符串常量的问题
- poj1265 & poj2954(皮克定理pick)在格点上的多边形求面积公式
- POJ - 3488 Arne Saknussemm(水题,细节题)
- getHibernateTemplate()的方法介绍
- oracle 快速删除表中的所有记录
- 第2周-项目5-数组作数据成员-工资类(文件读取)
- xstream实现xml与Object之间的自如转换
- Implement strStr()
- 新手对于iPhone开发环境等入门问题解答汇总
- getHibernateTemplate()
- Angularjs 控制器