ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
来源:互联网 发布:免费扫描软件 编辑:程序博客网 时间:2024/05/17 09:08
#1632 : Secret Poems
- 样例输入
5THSAD IIVOP SEOOH RGETI YMINK2ABCD4ABCDEFGHIJKLMNOP
- 样例输出
THISIPOEMSDNKIAOIHTVOGYREABDCABEIKHLFNPOCMJGD
描述
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.
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int n,x,ok,y;
char map1[101][101];
char map2[101][101];
char str[10001];
while(~scanf("%d",&n)){
for(int i=0;i<n;i++){
scanf("%s",map1[i]);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
map2[i][j]='@';
}
map2[i][n]='\0';
}
// printf("----------\n");
str[0]=map1[0][0];
ok=0,x=0,y=0;
int len=1;
while(len<n*n) {
if(x==0&&ok==0) {
if(y+1<n) {
y++;
ok=1;
}
else{
x++;
ok=1;
}
}
else if(y==0&&ok==1) {
if(x+1<n) {
x++;
ok=0;
}
else {
y++;
ok=0;
}
}
else {
if(ok==1) {
if(x+1<n&&y-1>=0) {
x++;
y--;
ok=1;
}else {
y++;
ok=0;
}
}
else if(ok==0) {
if(x-1>=0&&y+1<n) {
x--;
y++;
ok=0;
}else {
x++;
ok=1;
}
}
}
//printf("%d %d %d\n",x,y,ok);
str[len]=map1[x][y];
len++;
}
str[len]='\0';
x=y=0;
int s=0;
// for(int i=0;i<16;i++){
// str[i]=char('A'+i);
// }
//printf("%s\n",str);
for(int i=0;i<strlen(str);) {
while(y<n && map2[x][y]=='@') {
map2[x][y]=str[i++];
y++;
}
y=y-1;
x=x+1;
while(x<n &&map2[x][y]=='@'){
map2[x][y]=str[i++];
x++;
}
y=y-1;
x=x-1;
while(y>=0 &&map2[x][y]=='@'){
map2[x][y]=str[i++];
y--;
}
x=x-1;
y=y+1;
while(x>=0&&map2[x][y]=='@'){
map2[x][y]=str[i++];
x--;
}
y=y+1;
x=x+1;
}
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
printf("%c",map2[i][j]);
}
printf("\n");
}
}
return 0;
}
- ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- Secret Poems 2017ACM-ICPC北京赛区/hihoCoder1632
- ACM-ICPC北京赛区2017网络同步赛 题目5 : Cats and Fish【模拟】
- ACM-ICPC北京赛区2015网络同步赛E:Stamps
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum-(线段树)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目1 : Visiting Peking University
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目1 : Visiting Peking University
- Visiting Peking University 2017ACM-ICPC亚洲区(北京赛区)网络赛题目1
- ACM-ICPC北京赛区(2017)网络赛-题目9 : Minimum(线段树)
- ACM/ICPC北京赛区网络赛
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛
- 2017 ACM-ICPC 亚洲区(北京赛区)网络赛
- ACM-ICPC北京赛区网络赛2017-minimum(线段树)
- ACM-ICPC 2017南宁赛区网络赛题目题解收集
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum(线段树)
- 2017ACM-ICPC亚洲区域赛北京站 F.Secret Poems(模拟)
- 2014 ACM/ICPC 北京赛区网络赛解题报告汇总
- 吴军《硅谷之谜》
- python计算列表内各元素的个数
- dubbo-registry分析
- Wireshark学习笔记——如何快速抓取HTTP数据包
- 关于如何修改CSDN中的字体大小和颜色
- ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
- C/汇编的混合编程
- 关于程序
- MD5加密详解
- 安卓的那些事儿-android之RecyclerView的使用,实现列表横向滚动
- C++中变量的作用域
- 机器学习(神经网络)
- [BZOJ1007][HNOI2008]水平可见直线(栈)
- 微信测试账号(验证成为开发者)总是配置失败