Emag eht htiw Em Pleh(POJ 2993)
~题目链接~
http://poj.org/problem?id=2993
输入
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
结果
+---+---+---+---+---+---+---+---+ |.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.| +---+---+---+---+---+---+---+---+
图示:white:大写字母,顺序从下往上
black:小写字母,顺序从上往下
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<ctype.h> 5 6 char map[10][10]; 7 8 int main() 9 { 10 char str[100]; 11 int i,j; 12 memset(map,0,sizeof(map)); 13 for(i=0; i<2; i++) 14 { 15 memset(str,0,sizeof(str)); 16 gets(str); 17 if(str[0]=='W') 18 { 19 int x,y; 20 int n=strlen(str); 21 for(j=7; j<n; j++) 22 { 23 if(isupper(str[j])) 24 { 25 char st=str[j]; 26 y=str[++j]-'a'; 27 x=8-str[++j]+'0'; 28 map[x][y]=st; 29 } 30 else if(islower(str[j])) 31 { 32 y=str[j++]-'a'; 33 x=8-str[j++]+'0'; 34 map[x][y]='P'; 35 } 36 } 37 } 38 else if(str[0]=='B') 39 { 40 int x,y; 41 int n=strlen(str); 42 for(j=7; j<n; j++) 43 { 44 if(isupper(str[j])) 45 { 46 char st=str[j]-'A'+'a'; 47 y=str[++j]-'a'; 48 x=8-str[++j]+'0'; 49 map[x][y]=st; 50 } 51 else if(islower(str[j])) 52 { 53 y=str[j++]-'a'; 54 x=8-str[j++]+'0'; 55 map[x][y]='p'; 56 } 57 } 58 } 59 } 60 for(i=0; i<8; i++) 61 { 62 printf("+---+---+---+---+---+---+---+---+ "); 63 for(j=0; j<8; j++) 64 { 65 int flag; 66 flag=(i+j)%2; 67 if(flag) 68 printf("|:"); 69 else 70 printf("|."); 71 if(map[i][j]) 72 printf("%c",map[i][j]); 73 else 74 { 75 if(flag) 76 printf(":"); 77 else 78 printf("."); 79 } 80 if(flag) 81 printf(":"); 82 else 83 printf("."); 84 85 } 86 printf("| "); 87 } 88 printf("+---+---+---+---+---+---+---+---+ "); 89 return 0; 90 }
Help Me with the Game(POJ 2996)模拟题
~题目链接~
http://poj.org/problem?id=2996
输入
+---+---+---+---+---+---+---+---+ |.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.| +---+---+---+---+---+---+---+---+
结果
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
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<ctype.h> 5 6 int flag; 7 char s[40],map[8][8]; 8 9 void find1(char str) 10 { 11 for(int i=7; i>=0; i--) 12 for(int j=0; j<8; j++) 13 if(map[i][j]==str) 14 { 15 if(!flag) 16 flag=1; 17 else 18 printf(","); 19 if(str!='P') 20 printf("%c",str); 21 printf("%c%d",j+'a',8-i); 22 } 23 } 24 25 void find2(char str) 26 { 27 for(int i=0; i<8; i++) 28 for(int j=0; j<8; j++) 29 if(map[i][j]==str) 30 { 31 if(!flag) 32 flag=1; 33 else 34 printf(","); 35 if(str!='p') 36 printf("%c",toupper(str)); 37 printf("%c%d",j+'a',8-i); 38 } 39 } 40 41 int main() 42 { 43 gets(s); 44 for(int i=0; i<8; i++) 45 { 46 gets(s); 47 for(int j=0; j<8; j++) 48 { 49 if(isalpha(s[4*(j+1)-2])) 50 map[i][j]=s[4*(j+1)-2]; 51 } 52 gets(s); 53 } 54 flag=0; 55 printf("White: "); 56 find1('K');find1('Q');find1('R');find1('B');find1('N');find1('P'); 57 printf(" "); 58 flag=0; 59 printf("Black: "); 60 find2('k');find2('q');find2('r');find2('b');find2('n');find2('p'); 61 printf(" "); 62 return 0; 63 }