POJ 2996 Help Me with the Game

来源:互联网 发布:机械制图用什么软件 编辑:程序博客网 时间:2024/04/25 22:24

模拟题哇。。

注意一下,白棋先按行数(棋盘的行编号)升序排,然后按照列升序排。

黑棋先按行数(棋盘的编号)降序排,然后按照列升序排。

#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");}


原创粉丝点击