Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴代码

Posted by dw_tanshunwen at 2012-12-06 01:02:48 on Problem 2993
#include <stdio.h>
#include <string.h>

char strData[100];
char chessName[] = ":KQRBNPkqrbnp";

int chessBoard[20][20];

void processChessData(char chessData[], int add)
{
	int type = add + 5;
	int row, col;
	for (int i = 0; chessData[i] != '\0'; ++ i)
	{
		if (strData[i] == ',')
		{
			continue;
		}

		if (strData[i] >= 'A' && strData[i] <= 'Z')
		{
			switch (strData[i])
			{
			case 'K':
				type = add + 0;
				break;
			case 'Q':
				type = add + 1;
				break;
			case 'R':
				type = add + 2;
				break;
			case 'B':
				type = add + 3;
				break;
			case 'N':
				type = add + 4;
				break;
			}
			continue;
		}

		if (strData[i] >= 'a' && strData[i] <= 'z')
		{
			col = strData[i] - 'a';
			continue;
		}

		if (strData[i] >= '0' && strData[i] <= '9')
		{
			row = '8' - strData[i];
			chessBoard[row][col] = type;

			type = add + 5;
			continue;
		}
	}
}

void inputData()
{
	memset(chessBoard, 0, sizeof(chessBoard));

	scanf("%s", &strData);
	scanf("%s", &strData);
	processChessData(strData, 1);
	scanf("%s", &strData);
	scanf("%s", &strData);
	processChessData(strData, 7);
}

void process()
{
	for (int i = 0; i < 17; ++ i)
	{
		if ((i & 1) == 0)
		{
			printf("+---+---+---+---+---+---+---+---+\n");
			continue;
		}

		printf("|");

		char color = '.';
		int row = ((i - 1) >> 1);
		if (row & 1)
		{
			color = ':';
		}

		for (int j = 0; j < 8; ++ j)
		{
			printf("%c", color);
			if (chessBoard[(i - 1) >> 1][j] == 0)
			{
				printf("%c", color);
			}
			else
			{
				printf("%c", chessName[chessBoard[row][j]]);
			}
			printf("%c|", color);

			if (color == '.')
			{
				color = ':';
			}
			else
			{
				color = '.';
			}
		}
		printf("\n");
	}
}

int main()
{
	inputData();
	process();
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator