#1632 : Secret Poems

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

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.

样例输入
5
THSAD
IIVOP
SEOOH
RGETI
YMINK
2
AB
CD
4
ABCD
EFGH
IJKL
MNOP
样例输出
THISI
POEMS
DNKIA
OIHTV
OGYRE
AB
DC
ABEI
KHLF
NPOC
MJGD
/*
模拟
*/ #include <bits/stdc++.h> #define MAXN 123 using namespace std; int n;
char str[MAXN][MAXN];
string s;
int x,y;
int pos;
int dir[][]={,,,-,,,-,};
int dir2[][]={,,,,,-,-,}; bool vis[MAXN][MAXN]; bool ok(int x,int y){
if(x<||x>=n||y<||y>=n||vis[x][y]==true)
return false;
return true;
} inline void init(){
memset(str,'\0',sizeof str);
memset(vis,false,sizeof vis);
pos=;
s="";
x=;
y=;
} int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<n;i++)
scanf("%s",str[i]);
while(true){
vis[x][y]=true;
s+=str[x][y];
bool flag=false;
int i;
for(i=;i<;i++){
int fx=x+dir[(pos+i)%][];
int fy=y+dir[(pos+i)%][];
if(ok(fx,fy)==true){
flag=true;
break;
}
}
if(flag==false)
break;
pos=(pos+i)%;
x+=dir[pos][];
y+=dir[pos][];
if(pos==||pos==)
pos=(pos+)%;
}
memset(vis,false,sizeof vis);
x=;y=;
pos=;
int cur=;
while(true){
vis[x][y]=true;
str[x][y]=s[cur++];
bool flag=false;
int i;
for(i=;i<;i++){
int fx=x+dir2[(pos+i)%][];
int fy=y+dir2[(pos+i)%][];
if(ok(fx,fy)==true){
flag=true;
break;
}
}
if(flag==false)
break;
pos=(pos+i)%;
x+=dir2[pos][];
y+=dir2[pos][];
}
for(int i=;i<n;i++){
for(int j=;j<n;j++){
printf("%c",str[i][j]);
}
printf("\n");
}
}
return ;
}

最新文章

  1. C#将WebBowser控件替换为Chrome内核
  2. 使用staruml学习画类图
  3. Android 呼吸灯流程分析
  4. opencv基于HSV的肤色分割
  5. CloudFoundry云环境中应用的特殊设计
  6. 在ios8上 [TableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];不起作用 经过测试加入下面方法 在ios7 8上都可以正常工作
  7. typescript中的工具 tsd
  8. iOS 使用 github
  9. MySQL之最基本命令
  10. 18 Ui美化 剪切动画clip
  11. SpringBoot单元测试
  12. (转载)python: getopt的使用;
  13. 【C#】WebApi 添加过滤器,实现对请求参数和响应内容的日志记录
  14. MySQL无损复制(转)
  15. GO slim
  16. mysql每天弹出窗口检测更新关闭方式...
  17. python之路---04 列表 元组
  18. CentOS7离线安装Ambari与HDP
  19. Smart/400开发上手2: COBOL批处理程序处理过程
  20. WCF使用net.tcp绑定的配置实例

热门文章

  1. 本地生成Rails API文档
  2. H5-基础-day01
  3. unity3d 角色头顶信息3D&amp;2D遮挡解决方案(一)
  4. 微信小程序—day02
  5. Appium(Python)驱动手机Chrome浏览器
  6. MySQL☞having子句
  7. Linux命令应用大词典-第16章 归档和压缩
  8. 使用SpringBoot整合ssm项目
  9. linux学习总结----redis总结
  10. 栈和队列ADT -数据结构(C语言实现)