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

花了近1个小时,1A,贴代码留念,勿喷SF-_-

Posted by blackRats at 2013-07-24 21:02:00 on Problem 2996
#include <cstdio>
#include <cstring>
#include <iomanip>
using namespace std;

char map[10][10];

bool first;

void find(char ch)
{
    for(int j=8;j>=1;j--)
    {
        for(int i=1;i<=8;i++)
        {
            if(map[i][j]==ch)
            {
                if(first)
                    first=false;
                else
                    printf(",");
                if(ch!='P' && ch!='p')
                    printf("%c",ch&(~32));
                printf("%c%d",i-1+'a',9-j);
            }
        }
    }
}

void find2(char ch)
{
    for(int j=1;j<=8;j++)
    {
        for(int i=1;i<=8;i++)
        {
            if(map[i][j]==ch)
            {
                if(first)
                    first=false;
                else
                    printf(",");
                if(ch!='P' && ch!='p')
                    printf("%c",ch&(~32));
                printf("%c%d",i-1+'a',9-j);
            }
        }
    }
}

int main()
{
//  freopen("in.txt","r",stdin);
    char str[200];

    gets(str);

    for(int j=1;j<=8;j++)
    {
        gets(str);
        for(int i=1;i<=8;i++)
        {
            char ch;
            if(isalpha(ch=str[4*i-2]))
            {
                map[i][j]=ch;
            }
        }
        gets(str);
    }

    printf("White: ");
    first=true;

    find('K');
    find('Q');
    find('R');
    find('B');
    find('N');
    find('P');

    printf("\nBlack: ");
    first=true;

    find2('k');
    find2('q');
    find2('r');
    find2('b');
    find2('n');
    find2('p');

    puts("");
}

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