模拟题哇。。
注意一下,白棋先按行数(棋盘的行编号)升序排,然后按照列升序排。
黑棋先按行数(棋盘的编号)降序排,然后按照列升序排。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
bool f;
char a[17][33];
void find1(char c)
{
int i,j,q,w;
f=false;
for (i=15,q=8; i>=1; i-=2,q--)
{
for (j=2,w=0; j<33; j+=4,w++)
{
if (a[i][j] == c)
{
if (c == 'P' || c == 'p')
{
if (f == true)
{
printf(",");
}
else
f=true;
printf("%c%d",'a'+w,9-q);
}
else
{
printf("%c%c%d,",c,'a'+w,9-q);
}
}
}
}
}
void find2(char c)
{
int i,j,q,w;
f=false;
for (i=1,q=1; i<17; i+=2,q++)
{
for (j=2,w=0; j<33; j+=4,w++)
{
if (a[i][j] == c)
{
if (c == 'P' || c == 'p')
{
if (f == true)
{
printf(",");
}
else
f=true;
printf("%c%d",'a'+w,9-q);
}
else
{
printf("%c%c%d,",c-32,'a'+w,9-q);
}
}
}
}
}
int main()
{
int i,j;
for (i=0; i<17; i++)
gets(a[i]);
printf("White: ");
find1('K');
find1('Q');
find1('R');
find1('B');
find1('N');
find1('P');
printf("\n");
printf("Black: ");
find2('k');
find2('q');
find2('r');
find2('b');
find2('n');
find2('p');
printf("\n");
}
本文介绍了一种用于棋盘布局的算法实现,该算法能够根据不同棋子类型进行特定的排序和展示。通过C++编程语言具体实现了黑白棋子的位置查找与格式化输出,适用于国际象棋等棋类游戏的布局显示。
683

被折叠的 条评论
为什么被折叠?



