poj 2996

题意  :看的太快   没注意题意  改了几次

#include<iostream>
#include<algorithm>
using namespace std;
struct Node
{
    int x,y;
    int sum;
}w[10][10],b[10][10];
bool cmp(Node x,Node y)
{
    if(x.x<y.x) return true;
    if(x.x==y.x) 
    {
        if(x.y<y.y) return true;
        return false;
    }
    return false;
}
int main()
{
    char a[111];
    int i,j,k;
    char c1,c2,c;
    memset(w,0,sizeof(w));
    memset(b,0,sizeof(b));
    for(i=8;i>=1;i--)
    {
        cin>>a;
        for(j=1;j<=8;j++)
        {
            cin>>c1>>c2;
            cin>>c;
            switch(c){
            case 'K':w[0][w[0][0].sum].x=i;w[0][w[0][0].sum].y=j;w[0][0].sum++;break;
            case 'Q':w[1][w[1][0].sum].x=i;w[1][w[1][0].sum].y=j;w[1][0].sum++;break;
            case 'R':w[2][w[2][0].sum].x=i;w[2][w[2][0].sum].y=j;w[2][0].sum++;break;
            case 'B':w[3][w[3][0].sum].x=i;w[3][w[3][0].sum].y=j;w[3][0].sum++;break;
            case 'N':w[4][w[4][0].sum].x=i;w[4][w[4][0].sum].y=j;w[4][0].sum++;break;
            case 'P':w[5][w[5][0].sum].x=i;w[5][w[5][0].sum].y=j;w[5][0].sum++;break;
            case 'k':b[0][b[0][0].sum].x=i;b[0][b[0][0].sum].y=j;b[0][0].sum++;break;
            case 'q':b[1][b[1][0].sum].x=i;b[1][b[1][0].sum].y=j;b[1][0].sum++;break;
            case 'r':b[2][b[2][0].sum].x=i;b[2][b[2][0].sum].y=j;b[2][0].sum++;break;
            case 'b':b[3][b[3][0].sum].x=i;b[3][b[3][0].sum].y=j;b[3][0].sum++;break;
            case 'n':b[4][b[4][0].sum].x=i;b[4][b[4][0].sum].y=j;b[4][0].sum++;break;
            case 'p':b[5][b[5][0].sum].x=i;b[5][b[5][0].sum].y=j;b[5][0].sum++;break;
            }
            cin>>c1;
        }
        cin>>c2;
    }
    cin>>a;
    //: King("K"), Queens ("Q"), Rooks ("R"), Bishops ("B"), Knights ("N"), and pawns
    for(i=0;i<=5;i++)
    {
    //    int sum=w[i][0].sum;
        for(j=0;j<w[i][0].sum-1;j++)
        {
            for(k=j+1;k<w[i][0].sum;k++)
                if(w[i][k].x<w[i][j].x)
                {
                    int x,y;
                    x=w[i][k].x;
                    y=w[i][k].y;
                    w[i][k].x=w[i][j].x;
                    w[i][k].y=w[i][j].y;
                    w[i][j].x=x;
                    w[i][j].y=y;
                }
                else if(w[i][k].x==w[i][j].x)
                {
                    if(w[i][k].y<w[i][j].y)
                    {
                        int x,y;
                    x=w[i][k].x;
                    y=w[i][k].y;
                    w[i][k].x=w[i][j].x;
                    w[i][k].y=w[i][j].y;
                    w[i][j].x=x;
                    w[i][j].y=y;
                    }
                }
        }
    }
    for(i=0;i<=5;i++)
    {
        int sum=b[i][0].sum;
        for(j=0;j<b[i][0].sum-1;j++)
        {
            for(k=j+1;k<b[i][0].sum;k++)
                if(b[i][k].x>b[i][j].x)
                {
                    int x,y;
                    x=b[i][k].x;
                    y=b[i][k].y;
                    b[i][k].x=b[i][j].x;
                    b[i][k].y=b[i][j].y;
                    b[i][j].x=x;
                    b[i][j].y=y;
                }
                else if(b[i][k].x==b[i][j].x)
                {
                    if(b[i][k].y<b[i][j].y)
                    {
                        int x,y;
                    x=b[i][k].x;
                    y=b[i][k].y;
                    b[i][k].x=b[i][j].x;
                    b[i][k].y=b[i][j].y;
                    b[i][j].x=x;
                    b[i][j].y=y;
                    }
                }
        }
    }

    cout<<"White: ";
    {
        if(w[0][0].sum>0)
        {
            
            for(i=0;i<w[0][0].sum;i++)
            cout<<'K'<<(char)(w[0][i].y+'a'-1)<<w[0][i].x<<',';
        }
        if(w[1][0].sum>0)
        {
            
            for(i=0;i<w[1][0].sum;i++)
            cout<<'Q'<<(char)(w[1][i].y+'a'-1)<<w[1][i].x<<',';
        }
        if(w[2][0].sum>0)
        {
            
            for(i=0;i<w[2][0].sum;i++)
            cout<<'R'<<(char)(w[2][i].y+'a'-1)<<w[2][i].x<<',';
        }
        if(w[3][0].sum>0)
        {
            
            for(i=0;i<w[3][0].sum;i++)
            cout<<'B'<<(char)(w[3][i].y+'a'-1)<<w[3][i].x<<',';
        }
        if(w[4][0].sum>0)
        {
            
            for(i=0;i<w[4][0].sum;i++)
            cout<<'N'<<(char)(w[4][i].y+'a'-1)<<w[4][i].x<<',';
        }
        if(w[5][0].sum>0)
        {
            
            for(i=0;i<w[5][0].sum-1;i++)
            cout<<(char)(w[5][i].y+'a'-1)<<w[5][i].x<<',';
            cout<<(char)(w[5][i].y+'a'-1)<<w[5][i].x;
        }
    
    }
    cout<<endl;
    cout<<"Black: ";
    {
        if(b[0][0].sum>0)
        {
            
            for(i=0;i<b[0][0].sum;i++)
            cout<<'K'<<(char)(b[0][i].y+'a'-1)<<b[0][i].x<<',';
        }
        if(b[1][0].sum>0)
        {
        
            for(i=0;i<b[1][0].sum;i++)
            cout<<'Q'<<(char)(b[1][i].y+'a'-1)<<b[1][i].x<<',';
        }
        if(b[2][0].sum>0)
        {
            
            for(i=0;i<b[2][0].sum;i++)
            cout<<'R'<<(char)(b[2][i].y+'a'-1)<<b[2][i].x<<',';
        }
        if(b[3][0].sum>0)
        {
            
            for(i=0;i<b[3][0].sum;i++)
            cout<<'B'<<(char)(b[3][i].y+'a'-1)<<b[3][i].x<<',';
        }
        if(b[4][0].sum>0)
        {
            
            for(i=0;i<b[4][0].sum;i++)
            cout<<'N'<<(char)(b[4][i].y+'a'-1)<<b[4][i].x<<',';
        }
        if(b[5][0].sum>0)
        {
        
            for(i=0;i<b[5][0].sum-1;i++)
            cout<<(char)(b[5][i].y+'a'-1)<<b[5][i].x<<',';
            cout<<(char)(b[5][i].y+'a'-1)<<b[5][i].x;
        }
    }
    cout<<endl;
    return 0;
}

 

posted @ 2014-05-31 10:17  _一千零一夜  阅读(202)  评论(0编辑  收藏  举报