zoukankan      html  css  js  c++  java
  • poj 2996 Help Me with the Game(模拟)

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

    题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按照KQRBNP的顺序

    白棋 输出 行小的 行相同按列小的 先输出 黑棋 行大的先输出

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<stack>
     6 #include<queue>
     7 #include<cmath>
     8 #include<algorithm>
     9 using namespace std;
    10 
    11 struct node
    12 {
    13     int p,x,y;
    14     char ch;
    15 }b[100],w[100];
    16 
    17 int tran(char c)
    18 {
    19     if(c=='K'||c=='k') return 1;
    20     if(c=='Q'||c=='q') return 2;
    21     if(c=='R'||c=='r') return 3;
    22     if(c=='B'||c=='b') return 4;
    23     if(c=='N'||c=='n') return 5;
    24     if(c=='P'||c=='p') return 6;
    25     return 0;
    26 }
    27 bool cmp_w(node x,node y)
    28 {
    29     if(x.p!=y.p) return x.p<y.p;
    30     if(x.x!=y.x) return x.x<y.x;
    31     return x.y<y.y;
    32 }
    33 
    34 bool cmp_b(node x,node y)
    35 {
    36     if(x.p!=y.p) return x.p<y.p;
    37     if(x.x!=y.x) return x.x>y.x;
    38     return x.y<y.y;
    39 }
    40 int main()
    41 {
    42     int sum_b=0,sum_w=0,i,j;
    43     char s[100],a;
    44     for(i=8; i>=1; i--)
    45     {
    46         gets(s);
    47         for(j=0; j<8; j++)
    48         {
    49             getchar(); getchar();
    50             scanf("%c",&a);
    51             getchar();
    52             if(a=='.'||a==':')
    53             continue;
    54             if(a>='A'&&a<='Z')
    55             {
    56                 w[sum_w].x=i;
    57                 w[sum_w].y=j;
    58                 w[sum_w].p=tran(a);
    59                 w[sum_w++].ch=a;
    60             }
    61             else
    62             {
    63                 b[sum_b].x=i;
    64                 b[sum_b].y=j;
    65                 b[sum_b].p=tran(a);
    66                 b[sum_b++].ch=a;
    67             }
    68         }
    69         getchar(); getchar();
    70     }
    71     gets(s);
    72     sort(w,w+sum_w,cmp_w);
    73     sort(b,b+sum_b,cmp_b);
    74     printf("White: ");
    75     for(i=0; i<sum_w; i++)
    76     {
    77         if(w[i].ch!='P')
    78         printf("%c",w[i].ch);
    79         if(i!=sum_w-1)
    80         printf("%c%d,",w[i].y+97,w[i].x);
    81         else
    82         printf("%c%d
    ",w[i].y+97,w[i].x);
    83     }
    84     printf("Black: ");
    85     for(i=0; i<sum_b; i++)
    86     {
    87         if(b[i].ch!='p')
    88         printf("%c",b[i].ch-32);
    89         if(i!=sum_b-1)
    90         printf("%c%d,",b[i].y+97,b[i].x);
    91         else
    92         printf("%c%d
    ",b[i].y+97,b[i].x);
    93     }
    94 
    95     return 0;
    96 }
  • 相关阅读:
    Leetcode 217 存在重复
    Leetcode 125验证回文串
    HTML标签
    Having dreams is what makes life tolerable.
    Database数据库——MySQL简述
    Python实践之路8——选课系统
    Python学习之路16——线程、进程和协程
    Python实践之路7——计算器
    Python学习之路14——Socket
    Python学习之路13——异常处理
  • 原文地址:https://www.cnblogs.com/bfshm/p/3237753.html
Copyright © 2011-2022 走看看