| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
贴代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator