zoukankan      html  css  js  c++  java
  • POJ2996Help Me with the Game

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

    又是一个大模拟题,表示做模拟题做的恶心,这个题主要是对数据的处理,从表格中将数据取出来再进行处理即可。

    主要注意的点就是:1.KQRBN五个大写字母输出的顺序,且p不输出。

                             2.输出白色的时候,按列升序排,列相同时按行升序排,黑色的是按列降序排,列相同的时候按行升序排。

                             3.最后是不用输出逗号的,这个用一个标记变量标记一下就行。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 using namespace std;
     5 char cont[] = "KQRBNP";
     6 char a,b,c;
     7 char map[19][20] ;
     8 int mark=1;
     9 void process(char ch,int colour,int &mark);
    10 void print(int colour);
    11 int main()
    12 {
    13     for(int i = 1 ; i <= 8 ; i++)
    14     {
    15         scanf("+---+---+---+---+---+---+---+---+");
    16         getchar();//消除换行符
    17         for(int j = 1 ; j <= 8 ; j++)
    18         {
    19             scanf("|%c%c%c",&a,&b,&c);
    20             map[i][j] = b ;//把每个方块里的内容读到map数组里
    21         }
    22         getchar();//消除每一行最后一个|
    23         getchar();//消除换行符
    24     }
    25     scanf("+---+---+---+---+---+---+---+---+");//输入最后一行
    26     getchar();//消除换行符
    27     print(1);//1代表输出白色
    28     cout<<endl;
    29     print(0);//2代表输出黑色
    30     cout<<endl;
    31     return 0;
    32 }
    33 void print(int colour)
    34 {
    35     if(colour == 1)
    36         cout<<"White:"<<' ';
    37     else
    38         cout<<"Black:"<<' ';
    39     int mark = 1;
    40     for(int i = 0 ; i <  6 ; i++)
    41     {
    42         process(cont[i],colour,mark);
    43     }
    44 }
    45 void process(char ch,int colour,int &mark)//这里的mark是一定要加地址符的,因为他的值是要改变的
    46 {
    47     //int markk = 1;
    48     char sh = ch ;
    49     if(colour == 0)
    50         ch += 32;
    51     if(colour == 0)
    52     {
    53         for(int i = 1 ; i <= 8 ; i++)//黑色输出的时候是列降序,列相同时行升序
    54         {
    55             for(int j = 1 ; j <= 8 ; j++)
    56             {
    57                 if(map[i][j] == ch)
    58                 {
    59                     if(mark)
    60                         mark = 0;//控制逗号的输出
    61                     else
    62                         printf(",");
    63                     if(ch != 'p'&&ch!='P')//p的时候只输出位置
    64                         printf("%c",sh);
    65                     printf("%c%d",j+'a'-1,9-i);
    66                 }
    67             }
    68         }
    69     }
    70 
    71     else
    72     {
    73         for(int i = 8 ; i >= 1 ; i--)//白色的输出的时候是列升序,列相同时行升序。
    74         {
    75             for(int j = 1 ; j <= 8 ; j++)
    76             {
    77                 if(map[i][j] == ch)
    78                 {
    79                     if(mark)
    80                         mark = 0;
    81                     else
    82                         printf(",");
    83                     if(ch != 'P'&&ch!='p')//等于p就不输出
    84                         printf("%c",sh);
    85                     printf("%c%d",j+'a'-1,9-i);
    86                 }
    87             }
    88         }
    89     }
    90 }
    View Code
  • 相关阅读:
    AtCoder Grand Contest 015 题解
    AtCoder Grand Contest 014 题解
    AtCoder Grand Contest 013 题解
    AtCoder Grand Contest 012 题解
    AtCoder Grand Contest 011 题解
    AtCoder Grand Contest 010 题解
    AtCoder Grand Contest 009 题解
    NOIP2017 Day2 题解
    博客园主题备份
    多项式全家桶
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3246535.html
Copyright © 2011-2022 走看看