Emag eht htiw Em Pleh
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3492 | Accepted: 2294 |
Description
This problem is a reverse case of the
problem 2996. You are given the output of the problem H and your task is to find the corresponding input.
Input
according to output of
problem 2996.
Output
according to input of
problem 2996.
Sample Input
White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4 Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
Sample Output
+---+---+---+---+---+---+---+---+ |.r.|:::|.b.|:q:|.k.|:::|.n.|:r:| +---+---+---+---+---+---+---+---+ |:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.| +---+---+---+---+---+---+---+---+ |...|:::|.n.|:::|...|:::|...|:p:| +---+---+---+---+---+---+---+---+ |:::|...|:::|...|:::|...|:::|...| +---+---+---+---+---+---+---+---+ |...|:::|...|:::|.P.|:::|...|:::| +---+---+---+---+---+---+---+---+ |:P:|...|:::|...|:::|...|:::|...| +---+---+---+---+---+---+---+---+ |.P.|:::|.P.|:P:|...|:P:|.P.|:P:| +---+---+---+---+---+---+---+---+ |:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.| +---+---+---+---+---+---+---+---+
Source
题目意思:
与POJ 2996(http://blog.csdn.net/mikasa3/article/details/54630409)刚好相反,本题给定棋子位置,输出还原后的棋盘。
解题思路:
模拟题,白棋黑棋分别搞一搞,注意数组的范围不能开小了。
这题我本来用的C++输入输出,一直异常中断,错误提示如下:
*** glibc detected *** ./prog: free(): invalid pointer: 0x08fc0028 ***
======= Backtrace: =========
/lib/libc.so.6[0x557f41f5]
/lib/libc.so.6(cfree+0x9c)[0x557f5acc]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x5571f2e1]
/usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0x556fbb2d]
/usr/lib/libstdc++.so.6(_ZNSs7reserveEj+0xad)[0x556fd73d]
/usr/lib/libstdc++.so.6(_ZNSs6appendEPKcj+0x8d)[0x556fd93d]
/usr/lib/libstdc++.so.6(_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_E+0x169)[0x556d6a89]
./prog(__gxx_personality_v0+0x453)[0x8048dbb]
./prog(__gxx_personality_v0+0x79)[0x80489e1]
======= Memory map: ========
看了蛮久不知道哪儿错了,遂改成C的输入输出,运行正常,AC。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int col(char c)//输出列
{
if(c=='a')return 2;
else if(c=='b') return 6;
else if(c=='c') return 10;
else if(c=='d') return 14;
else if(c=='e') return 18;
else if(c=='f') return 22;
else if(c=='g') return 26;
else if(c=='h') return 30;
return 0;
}
int row(char c)//输出行
{
if(c=='1') return 15;
else if(c=='2') return 13;
else if(c=='3') return 11;
else if(c=='4') return 9;
else if(c=='5') return 7;
else if(c=='6') return 5;
else if(c=='7') return 3;
else if(c=='8') return 1;
return 0;
}
char ma[18][34];
void Init()//将边框和.和:插入到相应位置
{
char frame[34]= {'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-',
'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'
};
for(int i=0; i<17; i+=2)
for(int j=0; j<33; j++)
ma[i][j]=frame[j];
for(int i=1; i<17; i+=2)
for(int j=0; j<33; j+=4)
ma[i][j]='|';
int t;
for(int i=1; i<17; i+=4)
for(int j=1; j<33; j+=8)
{
for(int k=0; k<3; ++k)
{
t=j;
ma[i][j+k]='.';
}
j=t;
}
for(int i=3; i<17; i+=4)
for(int j=1; j<33; j+=8)
{
for(int k=0; k<3; ++k)
{
t=j;
ma[i][j+k]=':';
}
j=t;
}
for(int i=1; i<17; i+=4)
for(int j=5; j<33; j+=8)
{
for(int k=0; k<3; ++k)
{
t=j;
ma[i][j+k]=':';
}
j=t;
}
for(int i=3; i<17; i+=4)
for(int j=5; j<33; j+=8)
{
for(int k=0; k<3; ++k)
{
t=j;
ma[i][j+k]='.';
}
j=t;
}
}
void output()//输出棋盘
{
for(int i=0; i<17; i++)
{
for(int j=0; j<33; j++)
printf("%c",ma[i][j]);
printf("\n");
}
}
int main()
{
Init();
int cas=2;
char color[10];
#ifdef ONLINE_JUDGE
#else
freopen("F:/cb/read.txt","r",stdin);
//freopen("F:/cb/out.txt","w",stdout);
#endif
while(cas--)
{
scanf("%s",color);
if(!strcmp(color,"White:"))//比较结果为0则匹配成功
{
char str[50];
scanf("%s",str);
char s[3];
int cnt=0;
for(int i=0; i<strlen(str); ++i)
{
if(str[i]==',')//以逗号为分隔点分别处理各个位置
{
if(s[0]>='A'&&s[0]<='Z')
ma[row(s[2])][col(s[1])]=s[0];
else if(s[0]>='a'&&s[0]<='z')
ma[row(s[1])][col(s[0])]='P';
cnt=0;
}
else s[cnt++]=str[i];
}
if(s[0]>='a'&&s[0]<='z')//注意最后一个位置的后面是没有逗号的所以要单独处理
ma[row(s[1])][col(s[0])]='P';
}
else if(!strcmp(color,"Black:"))
{
char str[70];
scanf("%s",str);
char s[3];
memset(s,'\0',sizeof(s));
int cnt=0,pos;
for(int i=0; i<strlen(str); ++i)
{
if(str[i]==',')
{
if(s[0]>='A'&&s[0]<='Z')
ma[row(s[2])][col(s[1])]=tolower(s[0]);
else if(s[0]>='a'&&s[0]<='z')
ma[row(s[1])][col(s[0])]='p';
cnt=0;
memset(s,'\0',sizeof(s));
}
else s[cnt++]=str[i];
}
if(s[0]>='a'&&s[0]<='z')
ma[row(s[1])][col(s[0])]='p';
}
}
output();
return 0;
}
/*
White:
Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
Black:
Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
*/