poj 2996 Help Me with the Game

poj 2996 Help Me with the Game

题意: 给你一个图表,表内大写的“k,q,b,r,n,p”表示白,小写的表黑;制表的最后一行为1,第一列为A,要求输出白和黑的字母位置,按其要求的顺序。(白:先按类型K>Q>R>B>N>P,从下行往上行,从左列往右列;黑:先按类型K>Q>R>B>N>P,从上行往下行,从左列往右列;)
题解: 没啥意思的模拟题,二维数组处理出表,然后按顺序查找就好了,锻炼下代码能力。。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 100;
char p[N][N];
char s[6] = {'K','Q','R','B','N','P'};
int have,m;
void print1(char x)
{
    for(int i = 16; i >= 0; i--)
    {
        if(i%2)
        {
            int id = 0;
            for(int j = 0; j < m; j++)
            {
                if(p[i][j] == '|')
                    id++;
                else if(p[i][j] == x)
                {
                    if(!have)
                        have++;
                    else
                        printf(",");
                    if(x != 'P')
                        printf("%c",x);
                    printf("%c%d",id+'a'-1,8-i/2);
                }
            }
        }
    }
}
void print2(char x)
{
    for(int i = 0; i <= 16 ; i++)
    {
        if(i%2)
        {
            int id = 0;
            for(int j = 0; j < m; j++)
            {
                if(p[i][j] == '|')
                    id++;
                else if(p[i][j] == x)
                {
                    if(!have)
                        have++;
                    else
                        printf(",");
                    if(x != 'p')
                        printf("%c",x-32);
                    printf("%c%d",id+'a'-1,8-i/2);
                }
            }
        }
    }
}
int main()
{
    for(int i = 0; i < 17; i++)
        scanf("%s",p[i]);
    m = strlen(p[0]);
    printf("White: ");
    have = 0;
    for(int i = 0; i < 6; i++)
        print1(s[i]);
    puts("");
    printf("Black: ");
    have = 0;
    for(int i = 0; i < 6; i++)
        print2(s[i]+32);
    puts("");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值