• POJ 2993 Emag eht htiw Em Pleh【模拟画棋盘】


    链接:



    Emag eht htiw Em Pleh
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 2280   Accepted: 1531

    Description

    This problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the corresponding input.

    Input

    according to output of problem 2996.

    Output

    according to input of problem 2996.

    Sample Input

    White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
    Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6

    Sample Output

    +---+---+---+---+---+---+---+---+
    |.r.|:::|.b.|:q:|.k.|:::|.n.|:r:|
    +---+---+---+---+---+---+---+---+
    |:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.|
    +---+---+---+---+---+---+---+---+
    |...|:::|.n.|:::|...|:::|...|:p:|
    +---+---+---+---+---+---+---+---+
    |:::|...|:::|...|:::|...|:::|...|
    +---+---+---+---+---+---+---+---+
    |...|:::|...|:::|.P.|:::|...|:::|
    +---+---+---+---+---+---+---+---+
    |:P:|...|:::|...|:::|...|:::|...|
    +---+---+---+---+---+---+---+---+
    |.P.|:::|.P.|:P:|...|:P:|.P.|:P:|
    +---+---+---+---+---+---+---+---+
    |:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.|
    +---+---+---+---+---+---+---+---+

    Source


    题意:

          画棋盘
          前面 ',' 前有三个字符的就画上第一个字符
          如果只有二个字符的就画上字符P
          如果是白色的位置的, 字符画大写
          如果是黑色的位置的, 字符画小写



    注意:

    输入的字符小写字母代表方格所在的的"行"('a'为第一行, 从下往上数)
    数字代表方格的列, 
    处理输入的字符前,要先初始化棋盘
     

    坑:

          1,棋子数可能是能放满棋盘的任意多个。【我开始就是坑在了这里,问了下GJ才知道】
            2,可能先输入黑色,再输入白色
            3,P 不一定放在最后, 可能放在前面或中间


    算法:


    简单模拟



    思路:

    没什么思路,细心就好了=_=

    /*****************************************************
    Accepted	168 KB	0 ms	C++	2849 B
    题意:画棋盘
          前面 ',' 前有三个字符的就画上第一个字符
          如果只有二个字符的就画上字符P
          如果是白色的位置的, 字符画大写
          如果是黑色的位置的, 字符画小写
    
    注意:输入的字符小写字母代表方格所在的的"行"('a'为第一行, 从下往上数)
           数字代表方格的列, 处理输入的字符前,要先初始化棋盘
    
    坑:1,棋子数可能是能放满棋盘的任意多个。【我开始就是坑在了这里,问了下GJ才知道】
        2,可能先输入黑色,再输入白色
        3,P 不一定放在最后, 可能放在前面或中间
    
    算法:简单模拟
    
    思路:没什么思路,细心就好了=_=
    ******************************************************/
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    
    char chess[20][40];
    char s1[100];
    char s2[100];
    char s[100];
    
    void solve(char s[], int flag) // 1= white, 0 = black
    {
        int x,y;
        int len =strlen(s); //可能有任意多棋子,不能直接数
        for(int i = 0; i < len;) //P (p) 可能输入在前面,不能分开计算
        {
            if(s[i] >= 'A' && s[i] <= 'Z')
            {
                x = 2*(s[i+2]-'0') - 1;
                y = 4*(s[i+1]-'a'+1) - 2;
                if(flag) chess[x][y] = s[i];
                else chess[x][y] = s[i]+32;
                i += 4;
            }
            else if(s[i] >= 'a' && s[i] <= 'z')
            {
                x = 2*(s[i+1]-'0') - 1;
                y = 4*(s[i]-'a'+1) - 2;
                if(flag) chess[x][y] = 'P';
                else chess[x][y] = 'p';
                i += 3;
            }
        }
    }
    
    int main()
    {
        while(scanf("%s%s",s,s1) != EOF)
        {
            scanf("%s%s",s,s2);
    
            int flag1 = 1; //标记方格中两边的点
            int flag2 = 1; // 标记方格中中间的点
    
            for(int i = 0; i <= 16 ; i++) //初始化棋盘,如果看不懂,自己直接画一个赋值好了
            {
                if(i%2 == 0)//+ -
                {
                    for(int j = 0; j <= 32; j++)
                    {
                        if(j%4 == 0) chess[i][j] = '+';
                        else chess[i][j] = '-';
                    }
                }
    
                else if(i%2 == 1) // |  :: ..
                {
                    for(int j = 0; j <= 32; j += 4)
                    {
                        if(j%4 == 0)
                        {
                            chess[i][j] = '|';
    
                            //格子中两边的点
                            if(flag1 == 1)
                            {
                                chess[i][j+1] = ':';
                                chess[i][j+3] = ':';
                            }
                            else if(flag1 == 0)
                            {
                                chess[i][j+1] = '.';
                                chess[i][j+3] = '.';
                            }
                            flag1 = !flag1; //每行后面多填一个正好好标记下一行
    
                            //格子中中间的点
                            if(flag2 == 1)
                            {
                                chess[i][j+2] = ':';
                            }
                            else if(flag2 == 0)
                            {
                                chess[i][j+2] = '.';
                            }
                            flag2 = !flag2; //同上
                        }
                    }
                }
            }
    
            if(s[0] == 'W') //s2为白色,大写
            {
                solve(s1, 0);
                solve(s2, 1);
            }
            else //s2为黑色,小写
            {
                solve(s1, 1);
                solve(s2, 0);
            }
    
            for(int i = 16; i >= 0; i--)
            {
                for(int j = 0; j <= 32; j++)
                    printf("%c", chess[i][j]);
                printf("
    ");
            }
        }
        return 0;
    }
    




  • 相关阅读:
    MySQL GTID复制Slave跳过错误事务Id以及复制排错问题总结
    Git基础命令整理
    原创-公司项目部署交付环境预检查shell脚本
    解决SecureCRT超时自动断开的问题
    Linux设置显示中文和设置字体
    高等代数4 线性方程组
    高等代数3 行列式
    高等代数2 向量组
    高等代数1 矩阵
    离散数学4 组合数学
  • 原文地址:https://www.cnblogs.com/freezhan/p/3223870.html
Copyright © 2020-2023  润新知