ZCMU—1403

原创 2017年01月02日 22:49:18

1403: Arne Saknussemm

Time Limit: 1 Sec  Memory Limit: 128 MB
[Submit][Status][Web Board]

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.

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 as follows:

_

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

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. The length of a message, before scrambling, is at most 1000 characters, including spaces and line breaks.

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

【分析】

字符串处理,解密...倒过来就变成一个文章,然后'_'表示空格  '\'表示换行,代码中需要'\\',然后处理的时候去掉末尾的空格,头上的空格不需要去掉...嗯大概我英语太差了...一开始错在这个上...
【代码】
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char a[1050][1050];
char s[2000000];
int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		for (int i=0;i<n;i++) cin>>a[i];
		int len=0;
		int t=1;
		for (int j=strlen(a[0])-1;j>=0;j--)
			for (int i=n-1;i>=0;i--)
			{
			//	if (a[i][j]!='_') t=1;
				if (t) s[len++]=a[i][j];
			}
		t=0;
		for (int j=0;j<strlen(a[0]);j++)
			for (int i=0;i<n;i++)
				if (a[i][j]=='_') t++;
				else goto out;
		out:;
		for (int i=0;i<len-t;i++)
			if (s[i]=='_') printf(" ");
			else
			if (s[i]=='\\') printf("\n");
			else
				printf("%c",s[i]);
		printf("\n\n");
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

爱卡发卡平台ACCESS虚拟主机版v1403-2

  • 2015年01月07日 19:53
  • 10.48MB
  • 下载

毕向东1403

  • 2016年05月09日 05:27
  • 44.8MB
  • 下载

ZCMU-1107: 迟来的A+B

解决思路 原先以为很简单,随手写了一个,但是TLE,然后仔细看了一下题目,看到了dp小王子,那这道题就和动态规划有关,我就用两个数组,把sum的两个组成部分都通过递推存到数组里面,然后查询的时候直接...

【ZCMU1894】Power Eggs(鹰蛋问题dp)

题目链接题目大意: 一栋建筑有N层,现在又k个蛋,每个蛋都一样。 现要确定在最坏情况下蛋在第几层掉下会碎需要实验多少次。 如果在f层掉下,那么在f层下掉下都不会碎,在f层及以上掉下都会碎。 若...

ZCMU1543 Numbers

题意就是 给你一个数p,找满足下列条件的数的个数:                 1.D是P的因子;                  2.D和P的二进制数至少有一个相同;       所以解...

【ZCMU1893】String Game(博弈)

题目链接题目大意: 给你两个串a,b,a的长度不小于b 现在有两个人A,B,每次可以选择在a的头或尾删除一个字符,由B先。 直到a的长度等于b,如果此时a与b相等则A赢可以分为三种情况讨论。 ...

ZCMU 1803 2n皇后问题 (DFS)

给定一个n*n的棋盘,棋盘中有一些位置不能放皇后。现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行、同一列或同一条对角线上,任意的两个白皇后都不在同一行、同一列或同一条对角线上...

【zcmu1920】nazime's 友人帐(贪心,树形dp)

题目链接 原题题目没说根是多少。 但是连通块必须包含1,我们不妨以1为根。1.假设有个点i,那么如果以点i为根的子树上有点包含在所选取的块,那么也必定会对i这个点进行同样的操作。因为到1的路径中必...

ZCMU 1098 查找元素

1098: 查找元素Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1042  Solved: 167 [Submit][Status][Web B...

ZCMU-计算机网络第四章数据链路层

ZCMU-计算机网络第四章数据链路层 1.设立数据链路层的主要目的是将有差错的物理线路变为对网络层无差错的B.数据链路 2.帧传输中采取增加转义字符或0比特插入的目的是保证数据传输的C.透明性...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ZCMU—1403
举报原因:
原因补充:

(最多只允许输入30个字)