poj2993

本文介绍了一种使用C++实现的简单字符串处理方法,通过构建二维字符数组来映射特定的字符位置,并最终以棋盘格式输出这些字符。该方法涉及读取输入字符串、解析坐标与字符并填充到二维数组中。

可以认为这是一道简单的字符串处理题,只要把相应的值填入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;
}

转载于:https://www.cnblogs.com/rainydays/archive/2011/02/01/1948673.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值