求教.由于嵌套stl容器造成洛谷编译不通过的问题.
查看原帖
求教.由于嵌套stl容器造成洛谷编译不通过的问题.
287516
MesonoxianYao楼主2021/8/5 10:32
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void initMap(std::vector<std::vector<char>>*map,int x,int y)
{
	static std::vector<char> temp_map;
	for (int i = 0; i < y; i++)
		map->push_back(temp_map);
	for (int i = 0; i < y; i++)
		for (int j = 0; j < x; j++)
			(*map)[i].push_back(' ');
	return;
}
void printMap(std::vector<std::vector<char>>* map)
{
	for (int i = 0; i < map->size(); i++) {
		for (int j = 0; j < (*map)[i].size(); j++)
			std::cout << (*map)[i][j];
		std::cout << std::endl;
	}
	return;
}
void fillMap(std::vector<std::vector<char>>* map,std::string temp)
{
	for(int i=0,j=0;i<(*map)[2].size()&&j<temp.size();i++)
		if ((*map)[2][i] == 'X') {
			(*map)[2][i] = temp[j];
			j++;
		}
	return;
}

void wendyFrame(std::vector<std::vector<char>>* map, int x)
{
	static std::vector<std::vector<char>>ppf =
	{
		{'.','.','*','.','.'},
		{'.','*','.','*','.'},
		{'*','.','X','.','*'},
		{'.','*','.','*','.'},
		{'.','.','*','.','.'}
	};
	for (int i = 0; i < ppf.size(); i++)
		for (int j = 0; j < ppf.size(); j++)
			(*map)[i][j + x] = ppf[i][j];
	return;
}
void peterpanFrames(std::vector<std::vector<char>>* map,int x)
{
	static std::vector<std::vector<char>>ppf = 
	{
		{'.','.','#','.','.'},
		{'.','#','.','#','.'},
		{'#','.','X','.','#'},
		{'.','#','.','#','.'},
		{'.','.','#','.','.'}
	};
	for (int i = 0; i < ppf.size(); i++)
		for (int j = 0; j < ppf.size(); j++)
			(*map)[i][j+x] = ppf[i][j];
	return;
}
int main()
{
	std::string temp;
	std::vector<std::vector<char>>map;
	
	std::cin >> temp;
	initMap(&map, temp.size() * 4 + 1, 5);
	for (int i = 0; i < temp.size(); i++)
		if ((i+1) % 3)
			peterpanFrames(&map, i * 4);
		else
			wendyFrame(&map, i * 4);
	fillMap(&map, temp);
	printMap(&map);

	return 0;
}

各位大佬们...本来打算用覆盖的方法来解决该问题,但是由于嵌套STL容器中">>"的问题造成无法通过洛谷的编译... 请问各位大佬,该如何改动呢...?

2021/8/5 10:32
加载中...