zoukankan      html  css  js  c++  java
  • 【POJ2993】Emag eht htiw Em Pleh

    题目传送门

    本题知识点:模拟(如果对国际象棋不熟悉的同学可以先百度一下

    本题跟POJ2996是逆过来的操作,如果做过【POJ2996】的同学就不会对题意不理解的了。

    (以下默认您已AC【POJ2996】)

    个人觉得该题比【POJ2996】要麻烦一点,因为要创建一个棋盘(其实也不是什么麻烦事)

    创好棋盘后,再把棋子一个个地放回去就可以了,这步操作跟【POJ2996】有异曲同工之妙

    数据很小(快乐水题)

    #include<iostream>
    #include<cstdio>
    #include<string>
    using namespace std;
    const int H = 17;
    const int W = 33;
    char chess[40][40];
    string white, black;
    struct node{
        string pla;
    }w[20], b[20];
    
    void build(){
        for(int i = 1; i <= H; i++){
            if(i % 2 == 1){
                for(int j = 1; j <= W; j++){
                    if(j % 4 == 1) chess[i][j] = '+';
                    else chess[i][j] = '-';
                }
            }
            else if(i % 4 == 2){
                for(int j = 1; j <= W; ){
                    if(j % 4 == 1) {
                        chess[i][j] = '|';
                        j += 3;
                    }
                    else {
                        if(j % 8 == 4){
                            chess[i][j] = chess[i][j - 1] = chess[i][j - 2] = '.';
                            j++;
                        }
                        else {
                            chess[i][j] = chess[i][j - 1] = chess[i][j - 2] = ':';
                            j++;
                        }
                    }
                }
            }
            else if(i % 2 == 0){
                for(int j = 1; j <= W; ){
                    if(j % 4 == 1) {
                        chess[i][j] = '|';
                        j += 3;
                    }
                    else {
                        if(j % 8 == 4){
                            chess[i][j] = chess[i][j - 1] = chess[i][j - 2] = ':';
                            j++;
                        }
                        else {
                            chess[i][j] = chess[i][j - 1] = chess[i][j - 2] = '.';
                            j++;
                        }
                    }
                }
            }
        }
    }
    
    char turn(char x){
        if('A' <= x && x <= 'Z')
            x += 32;
        return x;
    }
    
    int main()
    {
        build();
    
        getline(cin, white);
        // White
        int cnt_w = 0, h, w;
        for(int i = 7; i < white.size(); ){
            if(white[i] == 'K' || white[i] == 'Q' || white[i] == 'R' || white[i] == 'B' || white[i] == 'N'){
                w = (white[i + 1] - 'a') * 4 + 3;
                char ch = white[i + 2];
                if(ch == '1') h = 16;
                else if(ch == '2') h = 14;
                else if(ch == '3') h = 12;
                else if(ch == '4') h = 10;
                else if(ch == '5') h = 8;
                else if(ch == '6') h = 6;
                else if(ch == '7') h = 4;
                else if(ch == '8') h = 2;
                chess[h][w] = white[i];
                i += 4;
            }
            else {
                w = (white[i] - 'a') * 4 + 3;
                char ch = white[i + 1];
                if(ch == '1') h = 16;
                else if(ch == '2') h = 14;
                else if(ch == '3') h = 12;
                else if(ch == '4') h = 10;
                else if(ch == '5') h = 8;
                else if(ch == '6') h = 6;
                else if(ch == '7') h = 4;
                else if(ch == '8') h = 2;
                chess[h][w] = 'P';
                i += 3;
            }
        }
    
        getline(cin, black);
        // Black
        int cnt_b = 0;
        for(int i = 7; i < black.size(); ){
            if(black[i] == 'K' || black[i] == 'Q' || black[i] == 'R' || black[i] == 'B' || black[i] == 'N'){
                w = (black[i + 1] - 'a') * 4 + 3;
                char ch = black[i + 2];
                if(ch == '1') h = 16;
                else if(ch == '2') h = 14;
                else if(ch == '3') h = 12;
                else if(ch == '4') h = 10;
                else if(ch == '5') h = 8;
                else if(ch == '6') h = 6;
                else if(ch == '7') h = 4;
                else if(ch == '8') h = 2;
                char b = turn(black[i]);
                chess[h][w] = b;
                i += 4;
            }
            else {
                w = (black[i] - 'a') * 4 + 3;
                char ch = black[i + 1];
                if(ch == '1') h = 16;
                else if(ch == '2') h = 14;
                else if(ch == '3') h = 12;
                else if(ch == '4') h = 10;
                else if(ch == '5') h = 8;
                else if(ch == '6') h = 6;
                else if(ch == '7') h = 4;
                else if(ch == '8') h = 2;
                chess[h][w] = 'p';
                i += 3;
            }
        }
    
        for(int i = 1; i <= H; i++) printf("%s
    ", chess[i] + 1);
    
        return 0;
    }
    
    
  • 相关阅读:
    RSA使用
    C#获取主机信息
    NSIS打包软件使用
    C#获取局域网主机
    C#实现Web链接启动应用程序
    4.布局介绍
    Server Sql 多表查询、子查询和分页
    C# File类常用方法
    Vue 使用技巧手记
    前端面试题手记
  • 原文地址:https://www.cnblogs.com/Ayanowww/p/11535233.html
Copyright © 2011-2022 走看看