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

1A , 贴代码!

Posted by windthenrain at 2015-03-01 10:44:35 on Problem 2996
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<algorithm>
using namespace std;
char st[40] , chess[10][40] ;
int a[9][9] ;

struct white
{
    char ch , row , col;
    int pow ;
}wh[100];

struct black
{
    char ch , row , col ;
    int pow ;
}bl[100];

bool cmp2 (white a , white b)
{
    if (a.pow < b.pow)
        return 1 ;
    if (a.pow > b.pow)
        return 0 ;
    if (a.pow == b.pow ) {
        if (a.row == b.row)
            return a.col < b.col ;
        else
            return a.row < b.row ;
    }
}

bool cmp1 (black a , black b)
{
    if (a.pow < b.pow)
        return 1 ;
    if (a.pow > b.pow)
        return 0 ;
    if (a.pow == b.pow ) {
        if (a.row == b.row)
            return a.col < b.col ;
        else
            return a.row > b.row ;
    }
}

int main ()
{
  //  freopen ("a.txt" , "r" , stdin) ;
    for (int i = 1 ; i <= 17 ; i++) {
        if (i & 1)
            gets (st) ;
        else
            gets (chess[i / 2]) ;
    }
    int k , f;

    for (int i = 1 ; i <= 8 ; i++) {
        k = 1 ;
        for (int j = 2 ; j < 33 ; j += 4 , k++) {
            switch ( chess[i][j] )
            {
                case 'k' : a[i][k] = 1 ; break ;
                case 'q' : a[i][k] = 2 ; break ;
                case 'r' : a[i][k] = 3 ; break ;
                case 'b' : a[i][k] = 4 ; break ;
                case 'n' : a[i][k] = 5 ; break ;
                case 'p' : a[i][k] = 6 ; break ;
                case 'K' : a[i][k] = -1 ; break ;
                case 'Q' : a[i][k] = -2 ; break ;
                case 'R' : a[i][k] = -3 ; break ;
                case 'B' : a[i][k] = -4 ; break ;
                case 'N' : a[i][k] = -5 ; break ;
                case 'P' : a[i][k] = -6 ; break ;
                case ':' : a[i][k] = 0 ; break ;
                case '.' : a[i][k] = 0 ; break ;
                default : break ;
            }
        }
    }
   /* for (int i = 1 ; i <= 8 ; i++) {
        for (int j = 1 ; j <= 8 ; j++) {
            printf ("%d\t" , a[i][j]) ;
        }
        puts ("") ;
    }*/
    k = 0 , f = 0 ;
    for (int i = 1 ; i <= 8 ; i++) {
        for (int j = 1 ; j <= 8 ; j++) {
            if (a[i][j] > 0) {
                bl[k].pow = a[i][j] ;
                bl[k].row = '0' + 9 - i ;
                bl[k].col = 'a' + j - 1 ;
                switch (a[i][j])
                {
                    case 1 : bl[k].ch = 'K' ; break ;
                    case 2 : bl[k].ch = 'Q' ; break ;
                    case 3 : bl[k].ch = 'R' ; break ;
                    case 4 : bl[k].ch = 'B' ; break ;
                    case 5 : bl[k].ch = 'N' ; break ;
                    default : break ;
                }
                k++ ;
            }
            if (a[i][j] < 0) {
                wh[f].pow = -a[i][j] ;
                wh[f].row = '0' + 9 - i ;
                wh[f].col = 'a' + j - 1 ;
                 switch (-a[i][j])
                {
                    case 1 : wh[f].ch = 'K' ; break ;
                    case 2 : wh[f].ch = 'Q' ; break ;
                    case 3 : wh[f].ch = 'R' ; break ;
                    case 4 : wh[f].ch = 'B' ; break ;
                    case 5 : wh[f].ch = 'N' ; break ;
                    default : break ;
                }
                f++ ;
            }
        }
    }

    sort (bl , bl + k , cmp1) ;
    sort (wh , wh + f , cmp2) ;

    printf ("White: ") ;
    for (int i = 0 ; i < f ; i++) {
       // printf ("wh[%d].pow = %d\n" , i , wh[i].pow) ;
        if (wh[i].pow != 6)
            printf ("%c" , wh[i].ch) ;
        printf ("%c%c" , wh[i].col , wh[i].row ) ;
        if (i != f - 1)
            printf (",") ;
    }
    puts ("") ;

    printf ("Black: ") ;
    for (int i = 0 ; i < k ; i++) {
        if (bl[i].pow != 6)
            printf ("%c" , bl[i].ch) ;
        printf ("%c%c" , bl[i].col , bl[i].row ) ;
        if (i != k - 1)
            printf (",") ;
    }
    puts ("") ;
    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