zoukankan      html  css  js  c++  java
  • POJ 2993 Emag eht htiw Em Pleh(模拟)

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

    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

    解题报告:这是一道模拟题,以国际象棋为背景,给我们分别描述白棋和黑棋的位置,让我们在固定的格式中填充,我们首先把图表打出来(在没有白棋和黑棋的情况下),在根据所给的信息,填充即可,剩下的就是找规律了,用到的是我们高中所学的等差数列的知识推出所给信息和row(行),col(列)之间的关系;
    代码如下:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    const int N = 110;
    char str[N];
    char map[17][34]={//打表
    "+---+---+---+---+---+---+---+---+",
    "|...|:::|...|:::|...|:::|...|:::|",
    "+---+---+---+---+---+---+---+---+",
    "|:::|...|:::|...|:::|...|:::|...|",
    "+---+---+---+---+---+---+---+---+",
    "|...|:::|...|:::|...|:::|...|:::|",
    "+---+---+---+---+---+---+---+---+",
    "|:::|...|:::|...|:::|...|:::|...|",
    "+---+---+---+---+---+---+---+---+",
    "|...|:::|...|:::|...|:::|...|:::|",
    "+---+---+---+---+---+---+---+---+",
    "|:::|...|:::|...|:::|...|:::|...|",
    "+---+---+---+---+---+---+---+---+",
    "|...|:::|...|:::|...|:::|...|:.:|",
    "+---+---+---+---+---+---+---+---+",
    "|:::|...|:::|...|:::|...|:::|...|",
    "+---+---+---+---+---+---+---+---+"
    };
    int Find1(char c)//确定所在行的函数
    {
    int row = c - '0';
    return 17 - row *2;
    }
    int Find2(char c)//确定所在列的函数
    {
    int col = c - 'a';
    return 4 * col + 2;
    }
    int main()
    {
    int i, j, row, col;// row表示行,col表示列
    gets(str);//因为输入时有空格,所以用gets比较方便
    for (i = 7; str[i] >= 'A' && str[i] <= 'Z'; i += 4)
    {
    row = Find1(str[i + 2]);
    col = Find2(str[i + 1]);
    map[row][col] = str[i];

    }
    for (j = i; str[j] >= 'a' && str[j] <= 'z'; j +=3)
    {
    row = Find1(str[j + 1]);
    col = Find2(str[j]);
    map[row][col] = 'P';//白棋是大写字母
    }
    memset(str, 0,sizeof(str));
    gets(str);
    for (i = 7; str[i] >= 'A' && str[i] <= 'Z'; i += 4)
    {
    row = Find1(str[i + 2]);
    col = Find2(str[i + 1]);
    map[row][col] = str[i] + 32; //因为黑棋是小写字母,而str[i]中存的是大写字母
    }
    for (j = i; str[j] >= 'a' && str[j] <='z'; j += 3)
    {
    row = Find1(str[j + 1]);
    col = Find2(str[j]);
    map[row][col] = 'p';
    }
    for (i = 0 ; i < 17; ++i)
    {
    for (j = 0; j < 33; ++j)
    {
    printf("%c", map[i][j]);
    }
    printf("\n");
    }
    return 0;
    }
  • 相关阅读:
    pgfplots画二维图真的很方便,多例比较
    LaTeX技巧206:使用gather输入多行公式的技巧
    LaTeX技巧205:使用split输入多行公式技巧
    LaTeX技巧207:使用align环境输入多行公式的技巧
    LaTeX技巧24:LaTeX常用命令集锦
    CTEX
    Latex常用指令学习
    LATEX数学公式基本语法
    LaTeX使用技巧
    C 命令行参数
  • 原文地址:https://www.cnblogs.com/lidaojian/p/2368065.html
Copyright © 2011-2022 走看看