poj 2996 Help Me with the Game

这是一道模拟题:要你找出黑白棋子的位置;注意要求;

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<vector>

using namespace std;

void Research1( char c , char map[][35] )

{

    int i ,  j,flag=1;

    for( i = 1 ; i <= 17; i ++ )

    {

         for( j = 1 ; j <= 33 ; j ++ )

             if( map[i][j]==c )    

             {    

                if( c>='A'&&c <='Z' ) printf( "%c",c );

                else printf( "%c",c-32 );

                printf( "%c%d,",'a'+j/4,i/2 );    

             }

    }

        

}

void Research2( char c , char map[][35] )

{

    int i ,  j,flag=1;

    for( i = 17 ; i >=1; i -- )

    {

         for( j = 1 ; j <= 33 ; j ++ )

             if( map[i][j]==c )    

             {    

                if( c>='A'&&c <='Z' ) printf( "%c",c );

                else printf( "%c",c-32 );

                printf( "%c%d,",'a'+j/4,i/2 );    

             }

    }

        

}

void Research_Black( char map[][35] )

{

    Research2( 'k' , map );

    Research2( 'q' , map );

    Research2( 'r' , map );

    Research2( 'b' , map );

    Research2( 'n' , map );

    int flag = 0;

    for( int i = 17 ; i >= 1 ; i -- )

    {

        for( int j = 1 ; j <= 33 ; j ++  )

        {

            if( map[i][j]=='p' )

            {

                if( flag )

                 printf( ",%c%d",'a'+j/4 ,i/2 );

                else printf( "%c%d",'a'+j/4 ,i/2 );    

                flag++;        

            }    

        }    

    }    

}

void Research_White( char map[][35] )

{

    Research1( 'K' , map );

    Research1( 'Q' , map );

    Research1( 'R' , map );

    Research1( 'B' , map );

    Research1( 'N' , map );

    int flag = 0;

    for( int i = 1 ; i <= 17 ; i ++ )

    {

        for( int j = 1 ; j <= 33 ; j ++  )

        {

            if( map[i][j]=='P' )

            {    

                if( flag )

                 printf( ",%c%d",'a'+j/4 ,i/2 );

                else printf( "%c%d",'a'+j/4 ,i/2 );    

                flag++;        

               

            }    

        }    

    }

}

int main(  )

{

     char map[35][35];

     while( scanf( "%s",map[17]+1 )==1 )

     {

        for( int i = 16 ; i >=1 ; i -- )

        {

             scanf( "%s",map[i]+1 );        

        }

           printf( "White: " );

        Research_White( map  );

        puts( "" );

        printf( "Black: " );

        Research_Black( map  );    

        puts( "" ); 

     }

    //system( "pause" );

    return 0;

}

 

你可能感兴趣的:(with)