//poj2996 模拟法 白 大写 黑 小写 白. 黑: 8-1 a-h 写得好浪费,应该简洁一些,比如使用面向对象的多态思想。
#include <iostream>
#include <string>
using namespace std;
char c[17][33];
int row[2][6][10]; //最多6个兵种, 王后车象马兵,最多有10个车/马/象
char col[2][6][10];
int num[2][6];
char w_role[5] = {
'K', 'Q', 'R', 'B', 'N'
};
void printw()
{
cout<<"White: K"<<col[0][0][0]<<row[0][0][0]<<",";
for(int i = 1; i < 5; i++)
{
for(int j = 0; j < num[0][i]; j++)
{
cout<<w_role[i]<<col[0][i][j]<<row[0][i][j]<<",";
}
}
for(int j = 0; j < num[0][5] - 1; j++)
cout<<col[0][5][j]<<row[0][5][j]<<",";
if(num[0][5] >= 1)
cout<<col[0][5][num[0][5] - 1]<<row[0][5][num[0][5] - 1]<<endl;
else
cout<<endl;
}
void printb()
{
cout<<"Black: K"<<col[1][0][0]<<row[1][0][0]<<",";
for(int i = 1; i < 5; i++)
{
for(int j = 0; j < num[1][i]; j++)
{
cout<<w_role[i]<<col[1][i][j]<<row[1][i][j]<<",";
}
}
for(int j = 0; j < num[1][5] - 1; j++)
cout<<col[1][5][j]<<row[1][5][j]<<",";
if(num[1][5] >= 1)
cout<<col[1][5][num[1][5] - 1]<<row[1][5][num[1][5] - 1]<<endl;
else
cout<<endl;
}
void dealw(int myRow, int myCol)
{
for(int i = myRow - 2; i >= 1; i--)
{
for(int j = 2; j < myCol - 2 ; j++)
{
if(c[i][j] == '+' || c[i][j] == '-' || c[i][j] == '|' || c[i][j] == '.' || c[i][j] == ':')
continue;
else
{
int row_pos = 8 - i / 2;
char col_pos = char('a' + (j / 2) / 2);
switch(c[i][j])
{
case 'K':
row[0][0][0] = row_pos;
col[0][0][0] = col_pos;
break;
case 'Q':
row[0][1][num[0][1]] = row_pos;
col[0][1][num[0][1]++] = col_pos;
break;
case 'R':
row[0][2][num[0][2]] = row_pos;
col[0][2][num[0][2]++] = col_pos;
break;
case 'B':
row[0][3][num[0][3]] = row_pos;
col[0][3][num[0][3]++] = col_pos;
break;
case 'N':
row[0][4][num[0][4]] = row_pos;
col[0][4][num[0][4]++] = col_pos;
break;
case 'P':
row[0][5][num[0][5]] = row_pos;
col[0][5][num[0][5]++] = col_pos;
break;
}
}
}
}
}
void dealb(int myRow, int myCol)
{
for(int i = 1; i < myRow - 1; i++)
{
for(int j = 2; j < myCol - 2 ; j++)
{
if(c[i][j] == '+' || c[i][j] == '-' || c[i][j] == '|' || c[i][j] == '.' || c[i][j] == ':')
continue;
else
{
int row_pos = 8 - i / 2;
char col_pos = char('a' + (j / 2) / 2);
switch(c[i][j])
{
case 'k':
row[1][0][0] = row_pos;
col[1][0][0] = col_pos;
break;
case 'q':
row[1][1][num[1][1]] = row_pos;
col[1][1][num[1][1]++] = col_pos;
break;
case 'r':
row[1][2][num[1][2]] = row_pos;
col[1][2][num[1][2]++] = col_pos;
break;
case 'b':
row[1][3][num[1][3]] = row_pos;
col[1][3][num[1][3]++] = col_pos;
break;
case 'n':
row[1][4][num[1][4]] = row_pos;
col[1][4][num[1][4]++] = col_pos;
break;
case 'p':
row[1][5][num[1][5]] = row_pos;
col[1][5][num[1][5]++] = col_pos;
break;
}
}
}
}
}
int main()
{
int myRow = 17;
int myCol = 33;
memset(num, 0, sizeof(num));
for(int i = 0; i < myRow; i++)
{
for(int j = 0; j < myCol; j++)
{
cin>>c[i][j];
}
}
dealw(myRow, myCol);
dealb(myRow, myCol);
printw();
printb();
return 0;
}
poj2996
最新推荐文章于 2015-08-04 18:15:49 发布