Poj 2996 Help Me with the Game
2010-09-04 14:22
381 查看
注意下规则
白色大写,黑色小写。
棋盘编号从下到上是1~8,从左到右是a~h
输出的时候类型都是大写,黑白棋的排序规则不一样。
1.按KQRBNP的优先顺序排。
2.相同类型白棋按行号小的排前面,黑棋按行号大的排前面。
3.相同列号按小排前面。
白色大写,黑色小写。
棋盘编号从下到上是1~8,从左到右是a~h
输出的时候类型都是大写,黑白棋的排序规则不一样。
1.按KQRBNP的优先顺序排。
2.相同类型白棋按行号小的排前面,黑棋按行号大的排前面。
3.相同列号按小排前面。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; char chess[50][50]; struct location{ int face,row,col; }; location white[64],black[64]; //K" (1), "Q" (2), "R" (3), "B" (4), "N" (5), or "P" (6). int change(char a,bool flag)//flag 0->black down 1->white UP { if (!flag) a=a-'a'+'A'; if (a=='K') return 1; if (a=='Q') return 2; if (a=='R') return 3; if (a=='B') return 4; if (a=='N') return 5; return 6; } char rever(int a) { if (a==1) return 'K'; if (a==2) return 'Q'; if (a==3) return 'R'; if (a==4) return 'B'; if (a==5) return 'N'; if (a==6) return 'P'; } bool cmp1(const location a,const location b)//black { if (a.face!=b.face) return a.face<b.face; if (a.row!=b.row) return a.row>b.row; return a.col<b.col; } bool cmp2(location a,location b)//white { if (a.face!=b.face) return a.face<b.face; if (a.row!=b.row) return a.row<b.row; return a.col<b.col; } int main() { int i,j,ii,jj,wcnt,bcnt; char x; while (scanf("%s",chess[0])!=EOF){ for (i=1;i<17;i++) scanf("%s",chess[i]); wcnt=bcnt=0; for (i=1,ii=8;i<17;i+=2,ii--) for (j=2,jj=0;j<33;j+=4,jj++){ if (chess[i][j]>='a'&&chess[i][j]<='z'){ black[bcnt].face=change(chess[i][j],0); black[bcnt].row=ii,black[bcnt++].col=jj; } else if (chess[i][j]>='A'&&chess[i][j]<='Z'){ white[wcnt].face=change(chess[i][j],1); white[wcnt].row=ii,white[wcnt++].col=jj; } } sort(black,black+bcnt,cmp1); sort(white,white+wcnt,cmp2); printf("White: "); for (i=0;i<wcnt;i++){ if (i) printf(","); x=rever(white[i].face); if (x!='P') printf("%c",x); printf("%c%d",white[i].col+'a',white[i].row); } printf("/nBlack: "); for (i=0;i<bcnt;i++){ 9376 if (i) printf(","); x=rever(black[i].face); if (x!='P') printf("%c",x); printf("%c%d",black[i].col+'a',black[i].row); } printf("/n"); } return 0; }
相关文章推荐
- Emag eht htiw Em Pleh(POJ 2993)、Help Me with the Game(POJ 2996)模拟题
- poj_2996 Help Me with the Game(模拟)
- POJ 2996 Help Me with the Game 国际象棋,模拟
- POJ 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- POJ2996-Help Me with the Game
- poj 2996 Help Me with the Game(模拟)
- POJ 2996-Help Me with the Game(模拟)
- POJ-2996-Help Me with the Game
- POJ2996-Help Me with the Game
- POJ 2996 Help Me with the Game(模拟)
- POJ 2996 Help Me with the Game
- poj2996 Help Me with the Game
- POJ 2996:Help Me with the Game 模拟题
- poj 2996 Help Me with the Game
- poj 2996 Help Me with the Game 模拟
- poj 2996--Help Me with the Game
- POJ-2996-Help Me with the Game
- poj-2996-2993-Help Me with the Game-模拟法
- poj-2993-Emag eht htiw Em Pleh && poj-2996-Help Me with the Game