• poj2993


    可以认为这是一道简单的字符串处理题,只要把相应的值填入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;
    }
  • 相关阅读:
    求转置矩阵问题
    喷水装置
    面试之谈
    迭代任意8种数据类型数组
    Session那点事
    随机验证码
    正则表达式:网页爬虫
    模拟上传服务端
    Properties集合的练习
    用递归算法对指定目录的深度遍历
  • 原文地址:https://www.cnblogs.com/rainydays/p/1948673.html
Copyright © 2020-2023  润新知