poj2993

摘要:poj2996问题的对应版本.基本思路就是读入所需要的坐标数据,存入一个字符数组,然后记录下作为分界线的符号,进行相应的格式变换就好.

#include<iostream>
#include "string"
#include<stdio.h>
#include "utility"
using namespace std;
const int cutoff1 = 1 - 'a',cutoff2 = 1 - '1';
char board[9][9];
const string s1 = "+---+---+---+---+---+---+---+---+";
const string s2 = "|:::|...|:::|...|:::|...|:::|...|";
const string s3 = "|...|:::|...|:::|...|:::|...|:::|";
void print()
{
    for (int line = 17; line != 0; --line)
    {       
        if (line % 2 == 0)
        {
           string ans = (line/2)%2 == 0 ? s3:s2;
            for (size_t i = 0; i != ans.size(); ++i)
            {
                if (i % 4 == 2)
                {
                    int index = (i - 2) / 4;
                    ans[i] = isalpha(board[line/2][index+1])?board[line/2][index+1]:ans[i];
                }
            }
            cout << ans << endl;
        }
        else
            cout << s1 << endl;
    }
}
int main()
{
    string name;
    for (int i = 1; i != 5; ++i)
    {
            cin >> name;
            if (name == "White:" || name == "Black:")
                continue;
            for (auto it = name.begin(); it != name.end();)
            {
                if (*it != ',')
                {
                    int x = isupper(*it) ? *(it + 2) + cutoff2 : *(it + 1) + cutoff2;
                    int y = isupper(*it) ? *(it + 1) + cutoff1 : *it + cutoff1;
                    board[x][y] = isupper(*it) ? (i==2?*it:tolower(*it)) : (i == 2 ? 'P' : 'p');
                    it += isupper(*it) ? 3 : 2;
                }
                else
                    ++it;
            }
    }
    print();
    return 0;
}

你可能感兴趣的:(poj)