| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 4565 | Accepted: 2887 |
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
Source
给出一个棋盘,大写字母是白色棋子,小写字母是黑色棋子。
先输出白棋再输出黑棋,格式为:类型+列数+行数。
按照KQRBNP的顺序输出棋子的位置,其中‘P’类型不输出‘P’。
在输入中出现相同类型的情况下,如果棋子是白色,较小行号优先,如果是黑色,则较大行号优先。
如果相同类型出现在同一行中,则较小列号的必须首先输出。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct Node
{
int x,y;//行、列
char c;
} ;
void col(int i)//输出列
{
if(i==2) cout<<"a";
else if(i==6) cout<<"b";
else if(i==10) cout<<"c";
else if(i==14) cout<<"d";
else if(i==18) cout<<"e";
else if(i==22) cout<<"f";
else if(i==26) cout<<"g";
else if(i==30) cout<<"h";
}
void row(int i)//输出行
{
if(i==15) cout<<"1";
else if(i==13) cout<<"2";
else if(i==11) cout<<"3";
else if(i==9) cout<<"4";
else if(i==7) cout<<"5";
else if(i==5) cout<<"6";
else if(i==3) cout<<"7";
else if(i==1) cout<<"8";
}
char ma[17][33];
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("F:/cb/read.txt","r",stdin);
//freopen("F:/cb/out.txt","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
Node q[9][9];//棋子位置
int cnt=0;//q中的列数
int wc=0,bc=0;//白棋和黑棋的数量
int no=0;//q中的行数
for(int i=0; i<9; ++i)//初始化置0
for(int j=0; j<9; ++j)
q[i][j].c='0';
for(int i=0; i<17; ++i)//输入原棋盘
{
if(i%2==1) ++no,cnt=0;
for(int j=0; j<33; ++j)
{
cin>>ma[i][j];
if((ma[i][j]>='A'&&ma[i][j]<='Z')||(ma[i][j]>='a'&&ma[i][j]<='z'))//字母才是棋子
{
q[no][cnt].x=i,q[no][cnt].y=j;
q[no][cnt++].c=ma[i][j];
//cout<<ma[i][j]<<" ";
if(ma[i][j]=='P') ++wc;
else if(ma[i][j]=='p') ++bc;
}
}
}
++cnt;
/*for(int j=8; j>=0; --j)//输出只有棋子的棋盘
{
for(int i=0; i<8; ++i)
cout<<q[j][i].c<<" ";
cout<<endl;
}
cout<<no<<" "<<cnt<<endl;*/
cout<<"White: ";
for(int j=no; j>=0; --j)
{
for(int i=0; i<cnt; ++i)
{
if(q[j][i].c=='K')
{
cout<<"K";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
}
}
for(int j=no; j>=0; --j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='Q')
{
cout<<"Q";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
for(int j=no; j>=0; --j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='R')
{
cout<<"R";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
for(int j=no; j>=0; --j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='B')
{
cout<<"B";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
for(int j=no; j>=0; --j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='N')
{
cout<<"N";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
int t=0,tt;
for(int j=no; j>=0; --j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='P')
{
++t;
if(t==wc)
{
t=i;
tt=j;
break;
}
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
col(q[tt][t].y);
row(q[tt][t].x);
cout<<endl;
cout<<"Black: ";
for(int j=0; j<cnt; ++j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='k')
{
cout<<"K";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
for(int j=0; j<cnt; ++j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='q')
{
cout<<"Q";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
for(int j=0; j<cnt; ++j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='r')
{
cout<<"R";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
for(int j=0; j<cnt; ++j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='b')
{
cout<<"B";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
for(int j=0; j<cnt; ++j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='n')
{
cout<<"N";
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
t=0;
for(int j=0; j<cnt; ++j)
for(int i=0; i<cnt; ++i)
if(q[j][i].c=='p')
{
++t;
if(t==wc)
{
t=i;
tt=j;
break;
}
col(q[j][i].y);
row(q[j][i].x);
cout<<",";
}
col(q[tt][t].y);
row(q[tt][t].x);
cout<<endl;
return 0;
}
/*
+---+---+---+---+---+---+---+---+
|.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.|
+---+---+---+---+---+---+---+---+
*/
因篇幅问题不能全部显示,请点此查看更多更全内容