Secret Poems(字符串处理)
来源:互联网 发布:战地1数据查询 编辑:程序博客网 时间:2024/06/05 18:55
Secret Poems
The Yongzheng Emperor (13 December 1678 – 8 October 1735), was the fifth emperor of the Qing dynasty of China. He was a very hard-working ruler. He cracked down on corruption and his reign was known for being despotic, efficient, and vigorous.
Yongzheng couldn’t tolerate people saying bad words about Qing or him. So he started a movement called “words prison”. “Words prison” means literary inquisition. In the famous Zhuang Tinglong Case, more than 70 people were executed in three years because of the publication of an unauthorized history of the Ming dynasty.
In short, people under Yongzheng’s reign should be very careful if they wanted to write something. So some poets wrote poems in a very odd way that only people in their friends circle could read. This kind of poems were called secret poems.
A secret poem is a N×N matrix of characters which looks like random and meaning nothing. But if you read the characters in a certain order, you will understand it. The order is shown in figure 1 below:
figure 1 figure 2
Following the order indicated by arrows, you can get “THISISAVERYGOODPOEMITHINK”, and that can mean something.
But after some time, poets found out that some Yongzheng’s secret agent called “Mr. blood dripping” could read this kind of poems too. That was dangerous. So they introduced a new order of writing poems as shown in figure 2. And they wanted to convert the old poems written in old order as figure1 into the ones in new order. Please help them.
There are no more than 10 test cases.
For each test case:
The first line is an integer N( 1 <= N <= 100), indicating that a poem is a N×N matrix which consist of capital letters.
Then N lines follow, each line is an N letters string. These N lines represent a poem in old order.
For each test case, convert the poem in old order into a poem in new order.
5THSAD IIVOP SEOOH RGETI YMINK2ABCD4ABCDEFGHIJKLMNOP
THISIPOEMSDNKIAOIHTVOGYREABDCABEIKHLFNPOCMJGD题解:
字符串处理问题,自己模拟一下,注意不同的情况就行了。
代码:
#include<stdio.h>#include<string.h>char str1[110][110],str2[11000],n,s,str3[110][110];int dfs(int x,int y,int s){ str2[s]=str1[x][y]; if(x==n-1&&y==n-1)//找到最后一个时返回; return 0; if((y==0&&x%2!=0&&(n%2==0&&x<n-1||n%2!=0))||(y==n-1&&n%2==0&&x%2!=0&&x<n-1||y==n-1&&n%2!=0&&x%2==0))dfs(x+1,y,s+1); /*1、在第一列,行的下标为偶数时;(1)n为偶数,并且不在最后一行时; (2)n为奇数时; 2、在最后一列时:(1)n为偶数,行的下标不为偶数,且不在最后一行时; (2)n为奇数,行的下标为偶数时; 以上情况都是(x,y)=>(x+1,y); */ else if((x==0&&y%2==0&&(n%2!=0&&y<n-1||n%2==0))||x==n-1&&(n%2==0&&y%2==0&&y<n-1||n%2!=0&&y%2!=0))dfs(x,y+1,s+1);/* 1、在第一行,列数为偶数时:(1)n为偶数; (2)n为奇数,且不为最后一列时; 2、在最后一行时:(1)n为偶数,列的下标为偶数,且不为最后一列时; (2)n为奇数,列的下标为奇数时; 以上情况都是(x,y)=>(x,y+1);*///除以上情况外: else if((x+y)%2==0)//行和列的下标之和为偶数时:(x,y)=>(x-1,y+1); dfs(x-1,y+1,s+1); else if((x+y)%2!=0)//行和列的下标之和为奇数时:(x,y)=>(x+1,y-1); dfs(x+1,y-1,s+1);}int print(int x,int y,int s){ str3[x][y]=str2[s]; if(s==n*n-1)return 0; if(str3[x][y+1]=='1'&&(x-1<0||str3[x-1][y]!='1'))//在第一行或需要转弯时,向右; print(x,y+1,s+1); else if(str3[x+1][y]=='1')//向下; print(x+1,y,s+1); else if(str3[x][y-1]=='1')//向左; print(x,y-1,s+1); else if(str3[x-1][y]=='1')//向上; print(x-1,y,s+1);}int main(){ int i,j; while(~scanf("%d",&n)) { for(i=0; i<n; i++) scanf("%s",str1[i]); dfs(0,0,0); for(i=0; i<n; i++) for(j=0; j<n; j++) str3[i][j]='1'; print(0,0,0); for(i=0; i<n; i++) for(j=0; j<n; j++) printf(j==n-1?"%c\n":"%c",str3[i][j]); }}
- Secret Poems(字符串处理)
- hihocoder 1632 Secret Poems
- Hihocoder 1632 : Secret Poems 思维|技巧
- hihoCoder-1632-Secret Poems(大模拟)
- Secret Poems 2017ACM-ICPC北京赛区/hihoCoder1632
- ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- 2017ACM-ICPC亚洲区域赛北京站 F.Secret Poems(模拟)
- uva 621 Secret Research(字符串水题)
- 【CF-496B】Secret Combination(最小字符串表示法)
- sort poems
- Secret Research ——字符串
- (UVA) Secret Research
- Secret
- Secret
- Secret
- Light oj 1338 - Hidden Secret!【字符串】
- Project 3: Sort Poems
- JAVA swing组件一些修饰方法
- 474. Ones and Zeroes
- 淘淘商城实战高并发分布式项目(2016.8月新版)
- js判断数组为空
- 兑换硬币(简单版,枚举)
- Secret Poems(字符串处理)
- HTML5 根据 一级下拉列表的选中项动态改变2级下拉列表的选项
- 欢迎使用CSDN-markdown编辑器
- 蓝桥杯训练:基础训练——质因数分解
- 同一进程的线程共享的资源和独有的资源
- RBM算法理解及推导
- 蓝桥杯:基础训练——矩阵乘法
- java:产生随机10个1000以内随机整数(从大到小)
- There is no getter for property named ‘XXX’ in 'class java.lang.String'