poj2996Help Me with the Game

来源:互联网 发布:二手软件 编辑:程序博客网 时间:2024/06/13 03:38

http://poj.org/problem?id=2996

模拟

#include <stdio.h>typedef struct node{    int x;    char y;    char ch;}Piece;Piece wPiece[16],bPiece[16];int n1,n2;char square[17][33];void findbp(char p){    int i,j;    for(i=1;i<=7;i++)    {        if(square[i][0]=='+')            continue;        for(j=0;j<32;j++)            if(square[i][j]==p)            {                bPiece[n1].ch=p-32;                bPiece[n1].x=9-(i+1)/2;//转换行号                bPiece[n1].y=(j+2)/4+96;//转换列号                n1++;            }    }       }void findwp(char p){    int i,j;    for(i=15;i>=9;i--)    {        if(square[i][0]=='+')            continue;        for(j=0;j<32;j++)            if(square[i][j]==p)            {                wPiece[n2].ch=p;                wPiece[n2].x=9-(i+1)/2;//转换行号                wPiece[n2].y=(j+2)/4+96;//转换列号                n2++;            }    }       }void chessNotation(Piece array[],int n)//输出象棋谱 {    int i;    for(i=0;i<n;i++)    {        if(array[i].ch!='P')        {            printf("%c%c%d,",array[i].ch,array[i].y,array[i].x);            continue;        }        if(i==n-1)            printf("%c%d\n",array[i].y,array[i].x);        else            printf("%c%d,",array[i].y,array[i].x);    }}int main(){    int i,j,t;    char bp[6]={'k','q','r','b','n','p'};    char wp[6]={'K','Q','R','B','N','P'};    for(i=0;i<17;i++)        scanf("%s",square[i]);    n1=0;    for(t=1;t<=6;t++)//6 times       findbp(bp[t-1]);    n2=0;    for(t=1;t<=6;t++)//6 times       findwp(wp[t-1]);    printf("White: ");    chessNotation(wPiece,n2);    printf("Black: ");    chessNotation(bPiece,n1);    return 0;}</span>


0 0
原创粉丝点击