加载中...

POJ 2993 - Emag eht htiw Em Pleh


问题描述

无。

解题思路

提示: 很烦很简单的国际象棋棋盘模拟,输入比较麻烦而已。

这题是 [POJ2996](.//Memory Time
//212K 0MS

#include
#include
using namespace std;

class whit
{
public:
int row;
char col;
char pie;
}ww[16];

class blac
{
public:
int row;
char col;
char pie;
}bb[16];

int main(void)
{
char white[63],black[63];
gets(white);
gets(black);

int x,y,z,r;

int count_w=0;
int count_b=0;
const int length_w=strlen(white);
const int length_b=strlen(black);

for(x=7,y=0;x<length_w;)
    if(white[x]>='B' && white[x]<='R')
    {
        ww[y].pie=white[x];
        ww[y].col=white[x+1];
        ww[y].row=white[x+2]-'0';  //字符转数字
        y++;
        x+=4;
        count_w++;
    }
    else if(white[x]>='a' && white[x]<='h')
    {
        ww[y].pie='P';
        ww[y].col=white[x];
        ww[y].row=white[x+1]-'0';
        y++;
        x+=3;
        count_w++;
    }
    else
        break;

    for(x=7,y=0;x<length_b;)
    if(black[x]>='B' && black[x]<='R')
    {
        bb[y].pie=black[x]+32;      //大写字母转换小写字母
        bb[y].col=black[x+1];
        bb[y].row=black[x+2]-'0';
        y++;
        x+=4;
        count_b++;
    }
    else if(black[x]>='a' && black[x]<='h')
    {
        bb[y].pie='p';
        bb[y].col=black[x];
        bb[y].row=black[x+1]-'0';
        y++;
        x+=3;
        count_b++;
    }
    else
        break;

    char chess[9]['i'];

    memset(chess,':',sizeof(chess));

    for(x=1;x<=7;x+=2)
        for(y='a';y<='g';y+=2)
            chess[x][y]='.';
    for(x=2;x<=8;x+=2)
        for(y='b';y<='h';y+=2)
            chess[x][y]='.';

    for(x=0;x<count_w;x++)
        chess[9-ww[x].row][ww[x].col]=ww[x].pie;

    for(x=0;x<count_b;x++)
        chess[9-bb[x].row][bb[x].col]=bb[x].pie;

    cout<<"+---+---+---+---+---+---+---+---+"<<endl;

    for(x=1,r=2;x<=7;x+=2,r+=2)
    {
        cout<<'|';
        for(y='a',z='b';y<='g';y+=2,z+=2)
            cout<<"."<<chess[x][y]<<".|:"<<chess[x][z]<<":|";
        cout<<endl;
        cout<<"+---+---+---+---+---+---+---+---+"<<endl;
        cout<<'|';
        for(y='a',z='b';y<='g';y+=2,z+=2)
            cout<<":"<<chess[r][y]<<":|."<<chess[r][z]<<".|";
        cout<<endl;
        cout<<"+---+---+---+---+---+---+---+---+"<<endl;
    }

return 0;

}


------


## 相关资料

- [北大 ACM - POJ 试题分类](https://exp-blog.com/algorithm/poj-shi-ti-fen-lei/)
- [北大 POJ 题库(官网在线)](http://poj.org/)
- [北大 POJ 题库(离线版)](https://github.com/EXP-Docs/POJ-Solving-Reports/doc/POJ%E7%A6%BB%E7%BA%BF%E7%89%88%E9%A2%98%E7%9B%AE.chm)
- [POJ封面书《程序设计导引及在线实践》](https://github.com/EXP-Docs/POJ-Solving-Reports/doc/程序设计导引及在线实践.pdf)
- [ACM 资料](https://lyy289065406.github.io/articles/tags/ACM/)

文章作者: EXP
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 EXP !
  目录