zoukankan      html  css  js  c++  java
  • poj 2993

    跟poj 2996反过来了,这里比较麻烦的就是处理白棋和黑棋各棋子对应的位置

    还有在最后打印棋盘式|,:,.的时候会有点繁琐(- - ACMer新手 );

    直接看代码吧;

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream> 
     4 using namespace std;
     5 char white[10][10],black[10][10];
     6 char s[]={"+---+---+---+---+---+---+---+---+"};
     7 int main()
     8 {    
     9     memset(white,'0',sizeof(white));
    10     memset(black,'0',sizeof(black));
    11     char x[50],y[50];
    12     gets(x);
    13     for(int i=0;i<strlen(x);++i){
    14         if((x[i]=='K'||x[i]=='Q'||x[i]=='R'||x[i]=='B'||x[i]=='N')&&i>5)
    15             white[x[i+2]-'0'][x[i+1]-'a'+1]=x[i],i+=3;
    16         if((x[i]>='a'&&x[i]<='h')&&i>5)
    17             white[x[i+1]-'0'][x[i]-'a'+1]='P',i+=2;
    18     }
    19     gets(y);
    20     for(int i=0;i<strlen(y);++i){
    21         if((y[i]=='K'||y[i]=='Q'||y[i]=='R'||y[i]=='B'||y[i]=='N')&&i>5)
    22             black[y[i+2]-'0'][y[i+1]-'a'+1]=y[i]-'A'+'a',i+=3;
    23         if((y[i]>='a'&&y[i]<='h')&&i>5)
    24             black[y[i+1]-'0'][y[i]-'a'+1]='p',i+=2;
    25     }
    26     cout << s << endl;
    27     for(int i=8;i>0;--i){
    28         cout << "|";
    29         for(int j=1;j<=8;++j){
    30             if(i%2==0){
    31                 if(j%2==1){
    32                     cout << ".";
    33                 if(white[i][j]!='0')    cout << white[i][j] << ".|";
    34                 else if(black[i][j]!='0')    cout << black[i][j] << ".|";
    35                 else    cout << "..|";
    36                 }
    37                 else if(j%2==0){
    38                     cout << ":";
    39                     if(white[i][j]!='0')    cout << white[i][j] << ":|";
    40                     else if(black[i][j]!='0')    cout << black[i][j] << ":|";
    41                     else    cout << "::|";
    42                 }
    43             }
    44             else{
    45                     if(j%2==1){
    46                         cout << ":";
    47                     if(white[i][j]!='0')    cout << white[i][j] << ":|";
    48                     else if(black[i][j]!='0')    cout << black[i][j] << ":|";
    49                     else    cout << "::|";
    50                     }
    51                     else{
    52                         cout << ".";
    53                         if(white[i][j]!='0')    cout << white[i][j] << ".|";
    54                         else if(black[i][j]!='0')    cout << black[i][j] << ".|";
    55                         else    cout << "..|";
    56                     }
    57             }
    58         }
    59         cout << endl << s << endl;
    60     }    
    61 } 
  • 相关阅读:
    Shell 查找和关闭进程
    如何重启MySQL,正确启动MySQL
    php 杂记
    Linux gcc编译简介、常用命令
    memset和printf(buf)编译出错
    Linux 文件操作函数
    Sizeof与Strlen的区别与联系
    获取Checkbox的值
    undefined reference to 'pthread_create'
    linux makefile文件
  • 原文地址:https://www.cnblogs.com/sasuke-/p/5118091.html
Copyright © 2011-2022 走看看