题目链接
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3551 | Accepted: 2279 |
Description
Input
Output
Sample Input
+---+---+---+---+---+---+---+---+ |.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.| +---+---+---+---+---+---+---+---+
Sample Output
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
题解:读清楚题意,暴力求解即可。
代码如下:
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<string> #include<queue> #include<stack> #include<map> #include<set> #include<stdlib.h> #include<vector> #define inff 0x3fffffff #define nn 410000 #define mod 1000000007 typedef long long LL; const LL inf64=inff*(LL)inff; using namespace std; char s[50][50]; vector<pair<int,int> >w[6],b[6]; map<char,int>ma; map<int,char>fma; void init() { ma['K']=0; fma[0]='K'; ma['Q']=1; fma[1]='Q'; ma['R']=2; fma[2]='R'; ma['B']=3; fma[3]='B'; ma['N']=4; fma[4]='N'; ma['P']=5; fma[5]='P'; int i; for(i=0;i<6;i++) { w[i].clear(); b[i].clear(); } } bool cmp(pair<int,int>x,pair<int,int>y) { if(x.first!=y.first) return x.first>y.first; return x.second<y.second; } int main() { init(); int i,j; for(i=0;i<17;i++) { scanf("%s",s[i]); } int x,y; for(i=1;i<=8;i++) { x=2*i-1; for(j=1;j<=8;j++) { y=4*j-2; if(s[x][y]>='A'&&s[x][y]<='Z') { w[ma[s[x][y]]].push_back(make_pair(9-i,j)); } if(s[x][y]>='a'&&s[x][y]<='z') { b[ma[s[x][y]-'a'+'A']].push_back(make_pair(9-i,j)); } } } for(i=0;i<=5;i++) { sort(w[i].begin(),w[i].end()); } for(i=0;i<=5;i++) { sort(b[i].begin(),b[i].end(),cmp); } printf("White: "); for(i=0;i<=4;i++) { for(j=0;j<(int)w[i].size();j++) printf("%c%c%d,",fma[i],w[i][j].second-1+'a',w[i][j].first); } int l=w[5].size(); for(i=0;i<l;i++) printf("%c%d%c",w[5][i].second-1+'a',w[5][i].first,i==l-1?'\n':','); printf("Black: "); for(i=0;i<=4;i++) { for(j=0;j<(int)b[i].size();j++) printf("%c%c%d,",fma[i],b[i][j].second-1+'a',b[i][j].first); } l=b[5].size(); for(i=0;i<l;i++) printf("%c%d%c",b[5][i].second-1+'a',b[5][i].first,i==l-1?'\n':','); return 0; }