4634046_ac_16ms_240k.cpp
来自「部分PKU上的源码」· C++ 代码 · 共 123 行
CPP
123 行
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct po
{
int column;
int row;
};
po p[9],P[9];
int pnumber,Pnumber;
string bss="kqrrbbnn";
int colw[9];
int roww[9];
bool usedw[9];
string wss="KQRRBBNN";
int colb[9];
int rowb[9];
bool usedb[9];
char ss[100];
void readit(char init,int row,int column)
{
if(init=='.'||init==':') return;
if(init=='p') {p[pnumber].row=row;p[pnumber].column=column;pnumber++;return;}
if(init=='P') {P[Pnumber].row=row;P[Pnumber].column=column;Pnumber++;return;}
for(int count=0;count<8;count++)
{
if(init==wss[count]&&usedw[count]==false)
{
roww[count]=row;colw[count]=column;
usedw[count]=true;
return;
}
if(init==bss[count]&&usedb[count]==false)
{
rowb[count]=row;colb[count]=column;
usedb[count]=true;
if(count>=2&&bss[count-1]==bss[count])
{
if(rowb[count]>rowb[count-1])
{
int temp;
temp=rowb[count];rowb[count]=rowb[count-1];rowb[count-1]=temp;
temp=colb[count];colb[count]=colb[count-1];colb[count-1]=temp;
}
}
return;
}
}
}
int comparew(const void *p1,const void *p2)
{
po t1=*(po*)p1;
po t2=*(po*)p2;
if(t1.row!=t2.row) return t1.row-t2.row;
else return t1.column-t2.column;
}
int compareb(const void *p1,const void *p2)
{
po t1=*(po*)p1;
po t2=*(po*)p2;
if(t1.row!=t2.row) return t2.row-t1.row;
else return t1.column-t2.column;
}
void getoutw()
{
bool first=true;
cout<<"White: ";
for(int count=0;count<8;count++)
{
if(usedw[count])
{
if(first) {first=false;}
else cout<<",";
cout<<wss[count]<<(char)('a'+colw[count]-1)<<roww[count];
}
}
qsort(P,Pnumber,sizeof(po),comparew);
for(int count2=0;count2<Pnumber;count2++)
{
cout<<","<<(char)(P[count2].column+'a'-1)<<P[count2].row;
}
cout<<endl;
}
void getoutb()
{
bool first=true;
cout<<"Black: ";
for(int count=0;count<8;count++)
{
if(usedb[count])
{
if(first) {first=false;}
else cout<<",";
cout<<wss[count]<<(char)('a'+colb[count]-1)<<rowb[count];
}
}
qsort(p,pnumber,sizeof(po),compareb);
for(int count2=0;count2<pnumber;count2++)
{
cout<<","<<(char)(p[count2].column+'a'-1)<<p[count2].row;
}
cout<<endl;
}
int main()
{
pnumber=0;Pnumber=0;
memset(usedw,false,sizeof(usedw));
memset(usedb,false,sizeof(usedb));
scanf("%[^\n]%*c",ss);
for(int ro=8;ro>=1;ro--)
{
scanf("%[^\n]%*c",ss);
for(int col=1;col<=8;col++)
{
readit(ss[col*4-2],ro,col);
}
scanf("%[^\n]%*c",ss);
}
getoutw();
getoutb();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?