POJ 2996

模拟,水

注意数组大小;

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using std::map;
using std::memset;
using std::sort;

char charmap[18][34];
char chess[8][8];
map<char, int> prior;

char get(int row,int col)
{
	row = 7 - row;
	row = 2 * row + 1;
	col = 4*col + 2;
	return charmap[row][col];
}

struct point
{
	char type;
	int i,j;
}White[100],Black[100];

int nw,nb;

bool cmp1(const point & a, const point &b)
{
	if(prior[a.type] == prior[b.type])
	{
		if(a.i == b.i)
		{
			return a.j < b.j;
		}
		return a.i < b.i;
	}
	else
	{
		return prior[a.type] < prior[b.type];
	}
}

bool cmp2(const point & a, const point &b)
{
	if(prior[a.type] == prior[b.type])
	{
		if(a.i == b.i)
		{
			return a.j < b.j;
		}
		return a.i > b.i;
	}
	else
	{
		return prior[a.type] < prior[b.type];
	}
}

int main()
{
	prior['K'] = 0;
	prior['k'] = 0;
	prior['Q'] = 1;
	prior['q'] = 1;
	prior['R'] = 2;
	prior['r'] = 2;
	prior['B'] = 3;
	prior['b'] = 3;
	prior['N'] = 4;
	prior['n'] = 4;
	prior['P'] = 5;
	prior['p'] = 5;

	for(int i = 0 ; i < 17; i++)
	{
		scanf("%s", charmap[i]);
	}

	for(int i = 0; i < 8; i++)
	{
		for(int j = 0 ; j < 8; j++)
		{
			if(get(i,j) == '.'|| get(i,j) == ':')
			{
				chess[i][j] = '0';
			}
			else
			{
				chess[i][j] = get(i,j);
				if('a' <= chess[i][j] && chess[i][j] <= 'z')
				{
					Black[nb].type = chess[i][j];
					Black[nb].i = i;
					Black[nb++].j = j;
				}
				else
				{
					White[nw].type = chess[i][j];
					White[nw].i = i;
					White[nw++].j = j;
				}
			}
		}
	}

	sort(White, White+nw, cmp1);
	sort(Black, Black+nb, cmp2);

	printf("White: ");
	for(int i = 0 ; i < nw; i++)
	{
		if(White[i].type != 'P')
		{
			printf("%c%c%d",White[i].type, White[i].j+'a', White[i].i+1);
		}
		else
		{
			printf("%c%d", White[i].j+'a', White[i].i+1);
		}
		if(i != nw-1)
		{
			printf(",");
		}
	}
	printf("\n");

	printf("Black: ");
	for(int i = 0 ; i < nw; i++)
	{
		if(Black[i].type != 'p')
		{
			printf("%c%c%d",Black[i].type+'A'-'a', Black[i].j+'a', Black[i].i+1);
		}
		else
		{
			printf("%c%d", Black[i].j+'a', Black[i].i+1);
		}
		if(i != nw-1)
		{
			printf(",");
		}
	}
	printf("\n");
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值