Help Me with the Game【模拟】

  给出一副国际象棋,有黑白两个阵营,我们想知道对应的每个阵营的棋子的所在的位置,如果有多个该类型的棋子,要按照固定的顺序输出。

白子:

  1. 按照KQRBNP的顺序输出,P类型不用输出字符,只用输出位置;
  2. 如果同种类型有多个棋子,按照y小的,然后是x小的;

黑子:

  1. 按照KQRBNP的顺序输出,P类型不用输出字符,只用输出位置;
  2. 如果同种类型有多个棋子,按照y大的,然后是x小的;

  从左往右,x依次递增,(a~h),从下往上,y依次递增,所以先输入的是y==8,(1~8)。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define eps 1e-8
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define MP(x, y) make_pair(x, y)
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
map<char, int> mp;
const char dir[7] = { ' ', 'K', 'Q', 'R', 'B', 'N', 'P' };
void init()
{
    mp['K'] = mp['k'] = 1;
    mp['Q'] = mp['q'] = 2;
    mp['R'] = mp['r'] = 3;
    mp['B'] = mp['b'] = 4;
    mp['N'] = mp['n'] = 5;
    mp['P'] = mp['p'] = 6;
}
inline bool Big_Char(char x) { return x >= 'A' && x <= 'Z'; }
struct node
{
    short x, y;
    node(short a=0, short b=0):x(a), y(b) {}
};
inline bool cmp_white(node e1, node e2) { return e1.y == e2.y ? e1.x < e2.x : e1.y < e2.y; }
inline bool cmp_black(node e1, node e2) { return e1.y == e2.y ? e1.x < e2.x : e1.y > e2.y; }
vector<node> w[7], b[7];
char s[10];
void del(int y)
{
    for(int i=1; i<=8; i++)
    {
        if(mp[s[i]])
        {
            if(Big_Char(s[i]))
            {
                w[mp[s[i]]].push_back(node(i, y));
            }
            else
            {
                b[mp[s[i]]].push_back(node(i, y));
            }
        }
    }
}
int main()
{
    init();
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(8);
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(7);
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(6);
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(5);
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(4);
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(3);
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(2);
    scanf("+---+---+---+---+---+---+---+---+\n");
    scanf("|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|\n", &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8]);
    del(1);
    scanf("+---+---+---+---+---+---+---+---+\n");
    bool fir;
    fir = false;
    printf("White: ");
    for(int i=1, len; i<=6; i++)
    {
        sort(w[i].begin(), w[i].end(), cmp_white);
        len = (int)w[i].size();
        for(int j=0; j<len; j++)
        {
            if(fir) printf(",");
            fir = true;
            if(i ^ 6) printf("%c", dir[i]);
            printf("%c%d", w[i][j].x + 'a' - 1, w[i][j].y);
        }
    }
    printf("\n");
    fir = false;
    printf("Black: ");
    for(int i=1, len; i<=6; i++)
    {
        sort(b[i].begin(), b[i].end(), cmp_black);
        len = (int)b[i].size();
        for(int j=0; j<len; j++)
        {
            if(fir) printf(",");
            fir = true;
            if(i ^ 6) printf("%c", dir[i]);
            printf("%c%d", b[i][j].x + 'a' - 1, b[i][j].y);
        }
    }
    printf("\n");
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wuliwuliii

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值