POJ 2993-Emag eht htiw Em Pleh(模拟-根据棋子位置还原棋盘)
来源:互联网 发布:ps10.0官方软件下载 编辑:程序博客网 时间:2024/06/10 18:12
Emag eht htiw Em Pleh
Time Limit: 1000MS Memory Limit: 65536KTotal 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,e4Black: 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
CTU Open 2005
题目意思:
与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,e4Black:Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6*/
0 0
- POJ 2993-Emag eht htiw Em Pleh(模拟-根据棋子位置还原棋盘)
- POJ 2993 Emag eht htiw Em Pleh【模拟画棋盘】
- POJ 2993Emag eht htiw Em Pleh(模拟)
- poj 2993 Emag eht htiw Em Pleh(模拟)
- POJ 2993 Emag eht htiw Em Pleh(模拟)
- POJ 2993 Emag eht htiw Em Pleh(模拟)
- POJ 2993 Emag eht htiw Em Pleh 大模拟
- POJ 2993:Emag eht htiw Em Pleh:模拟题
- POJ 2993 Emag eht htiw Em Pleh 模拟
- POJ 2993-Emag eht htiw Em Pleh(模拟)
- POJ 2993 Emag eht htiw Em Pleh(模拟)
- POJ 2993 Emag eht htiw Em Pleh 模拟,题意
- Poj 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- POJ 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- Poj 2993 Emag eht htiw Em Pleh
- POJ 2993:Emag eht htiw Em Pleh
- DOS CMD
- Java基本概念-ajax
- Centos服务器被挂马的一次抓马经历
- js print
- pat-bl-1029
- POJ 2993-Emag eht htiw Em Pleh(模拟-根据棋子位置还原棋盘)
- YARN与MapReduce的区别
- PAT甲级1038
- JVM垃圾收集器(1)--G1之前GC方法概览
- Java基本概念-jQuery
- jvm理论-class 再重新认识一下class
- Docker命令大全
- Discuz论坛系统搭建
- SpringMVC中拦截/和拦截/*的区别