poj 2996 Help Me with the Game(模拟)
2013-08-05 10:57
435 查看
题目:http://poj.org/problem?id=2996
题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按照KQRBNP的顺序
白棋 输出 行小的 行相同按列小的 先输出 黑棋 行大的先输出
题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按照KQRBNP的顺序
白棋 输出 行小的 行相同按列小的 先输出 黑棋 行大的先输出
#include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stack> #include<queue> #include<cmath> #include<algorithm> using namespace std; struct node { int p,x,y; char ch; }b[100],w[100]; int tran(char c) { if(c=='K'||c=='k') return 1; if(c=='Q'||c=='q') return 2; if(c=='R'||c=='r') return 3; if(c=='B'||c=='b') return 4; if(c=='N'||c=='n') return 5; if(c=='P'||c=='p') return 6; return 0; } bool cmp_w(node x,node y) { if(x.p!=y.p) return x.p<y.p; if(x.x!=y.x) return x.x<y.x; return x.y<y.y; } bool cmp_b(node x,node y) { if(x.p!=y.p) return x.p<y.p; if(x.x!=y.x) return x.x>y.x; return x.y<y.y; } int main() { int sum_b=0,sum_w=0,i,j; char s[100],a; for(i=8; i>=1; i--) { gets(s); for(j=0; j<8; j++) { getchar(); getchar(); scanf("%c",&a); getchar(); if(a=='.'||a==':') continue; if(a>='A'&&a<='Z') { w[sum_w].x=i; w[sum_w].y=j; w[sum_w].p=tran(a); w[sum_w++].ch=a; } else { b[sum_b].x=i; b[sum_b].y=j; b[sum_b].p=tran(a); b[sum_b++].ch=a; } } getchar(); getchar(); } gets(s); sort(w,w+sum_w,cmp_w); sort(b,b+sum_b,cmp_b); printf("White: "); for(i=0; i<sum_w; i++) { if(w[i].ch!='P') printf("%c",w[i].ch); if(i!=sum_w-1) printf("%c%d,",w[i].y+97,w[i].x); else printf("%c%d\n",w[i].y+97,w[i].x); } printf("Black: "); for(i=0; i<sum_b; i++) { if(b[i].ch!='p') printf("%c",b[i].ch-32); if(i!=sum_b-1) printf("%c%d,",b[i].y+97,b[i].x); else printf("%c%d\n",b[i].y+97,b[i].x); } return 0; }
相关文章推荐
- poj_2996 Help Me with the Game(模拟)
- poj 2996 Help Me with the Game 模拟
- POJ 2996-Help Me with the Game(模拟-描述棋盘中KQRBNP的位置)
- POJ 2996 Help Me with the Game 国际象棋,模拟
- poj-2996-2993-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(模拟)
- 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0
- 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 Help Me with the Game 模拟
- poj 2996 Help Me with the Game 模拟