可以认为这是一道简单的字符串处理题,只要把相应的值填入map对应的位置,然后把map输出就行了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
char map[9][9];
void init()
{
memset(map, 0, sizeof(map));
string st;
cin >> st;
getline(cin, st);
int i = 0;
while (st[i] != '\0')
{
i++;
char ch;
if (st[i] > 'Z')
ch = 'P';
else
{
ch = st[i];
i++;
}
int y = st[i++] - 'a' + 1;
int x = st[i++] - '0';
x = 9 - x;
map[x][y] = ch;
}
cin >> st;
getline(cin, st);
i = 0;
while (st[i] != '\0')
{
i++;
char ch;
if (st[i] > 'Z')
ch = 'p';
else
{
ch = st[i] + 'a' - 'A';
i++;
}
int y = st[i++] - 'a' + 1;
int x = st[i++] - '0';
x = 9 - x;
map[x][y] = ch;
}
}
void output()
{
string line = "+---+---+---+---+---+---+---+---+";
cout << line << endl;
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 9; j++)
{
char ch1 = map[i][j], ch;
if ((i + j) % 2 == 1)
ch = ':';
else
ch = '.';
if (ch1 == 0)
ch1 = ch;
printf("|%c%c%c", ch, ch1, ch);
}
cout << "|" << endl;
cout << line << endl;
}
}
int main()
{
//freopen("D:\\t.txt", "r", stdin);
init();
output();
return 0;
}