• POJ2993Emag eht htiw Em Pleh


    转载请注明出处:優YoU http://user.qzone.qq.com/289065406/blog/1299148520

     

    提示:很烦很简单的国际象棋棋盘模拟,输出比较麻烦而已。。。

    是POJ2996的相反情况,认真的同学会发现2993的题目和2996的题目是相反的。。。。

     

    POJ2996-Help Me with the Game

    POJ2993-Emag eht htiw Em Pleh

     

      1 //Memory Time 
    2 //212K 0MS
    3
    4
    5 #include<iostream>
    6 #include<string>
    7 using namespace std;
    8
    9 class whit
    10 {
    11 public:
    12 int row;
    13 char col;
    14 char pie;
    15 }ww[16];
    16
    17 class blac
    18 {
    19 public:
    20 int row;
    21 char col;
    22 char pie;
    23 }bb[16];
    24
    25 int main(void)
    26 {
    27 char white[63],black[63];
    28 gets(white);
    29 gets(black);
    30
    31 int x,y,z,r;
    32
    33 int count_w=0;
    34 int count_b=0;
    35 const int length_w=strlen(white);
    36 const int length_b=strlen(black);
    37
    38 for(x=7,y=0;x<length_w;)
    39 if(white[x]>='B' && white[x]<='R')
    40 {
    41 ww[y].pie=white[x];
    42 ww[y].col=white[x+1];
    43 ww[y].row=white[x+2]-'0'; //字符转数字
    44 y++;
    45 x+=4;
    46 count_w++;
    47 }
    48 else if(white[x]>='a' && white[x]<='h')
    49 {
    50 ww[y].pie='P';
    51 ww[y].col=white[x];
    52 ww[y].row=white[x+1]-'0';
    53 y++;
    54 x+=3;
    55 count_w++;
    56 }
    57 else
    58 break;
    59
    60 for(x=7,y=0;x<length_b;)
    61 if(black[x]>='B' && black[x]<='R')
    62 {
    63 bb[y].pie=black[x]+32; //大写字母转换小写字母
    64 bb[y].col=black[x+1];
    65 bb[y].row=black[x+2]-'0';
    66 y++;
    67 x+=4;
    68 count_b++;
    69 }
    70 else if(black[x]>='a' && black[x]<='h')
    71 {
    72 bb[y].pie='p';
    73 bb[y].col=black[x];
    74 bb[y].row=black[x+1]-'0';
    75 y++;
    76 x+=3;
    77 count_b++;
    78 }
    79 else
    80 break;
    81
    82 char chess[9]['i'];
    83
    84 memset(chess,':',sizeof(chess));
    85
    86 for(x=1;x<=7;x+=2)
    87 for(y='a';y<='g';y+=2)
    88 chess[x][y]='.';
    89 for(x=2;x<=8;x+=2)
    90 for(y='b';y<='h';y+=2)
    91 chess[x][y]='.';
    92
    93 for(x=0;x<count_w;x++)
    94 chess[9-ww[x].row][ww[x].col]=ww[x].pie;
    95
    96 for(x=0;x<count_b;x++)
    97 chess[9-bb[x].row][bb[x].col]=bb[x].pie;
    98
    99 cout<<"+---+---+---+---+---+---+---+---+"<<endl;
    100
    101 for(x=1,r=2;x<=7;x+=2,r+=2)
    102 {
    103 cout<<'|';
    104 for(y='a',z='b';y<='g';y+=2,z+=2)
    105 cout<<"."<<chess[x][y]<<".|:"<<chess[x][z]<<":|";
    106 cout<<endl;
    107 cout<<"+---+---+---+---+---+---+---+---+"<<endl;
    108 cout<<'|';
    109 for(y='a',z='b';y<='g';y+=2,z+=2)
    110 cout<<":"<<chess[r][y]<<":|."<<chess[r][z]<<".|";
    111 cout<<endl;
    112 cout<<"+---+---+---+---+---+---+---+---+"<<endl;
    113 }
    114
    115 return 0;
    116 }
  • 相关阅读:
    蓝桥杯程序设计 剪格子
    sql中 1<> 1=1的用处
    form表单的6种提交方式
    js中添加监听,判断是什么事件
    angular iFrame加载资源问题
    报表往子报表里传入list
    struts 文件上传
    获取运行时的泛型类型
    Dao层抽取BaseDao
    SSH整合总结
  • 原文地址:https://www.cnblogs.com/lyy289065406/p/2121389.html
Copyright © 2020-2023  润新知