尝试编译由4个字符串组成的550x550向量时出现“错误C1060:编译器空间不足”

时间:2018-11-27 09:18:07

标签: c++

此程序旨在读取网格中的字符串数组/向量(例如0101),以显示和解决迷宫问题。在输入20x20数组时可以使用,但是在尝试编译和运行550x550向量时收到“错误C1060:编译器空间不足”。

我已将/ Zm200添加到项目属性中,并以指数方式增加了堆提交大小。

我正在运行具有8GB RAM的x64位Windows 10并使用Visual Studio Professional 2017

// MazeBreaker.cpp : This file contains the 'main' function. Program execution begins && ends there.
//

#include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

//Creating Variables

vector<vector<string>> ExampleMaze = {
    {"1110", "1100", "1111", "1001", "1101", "1000", "1101", "1010", "1001", "1111", "1010", "1001", "1111", "1110", "1111", "1111", "1101", "1010", "1110", "1100"},
    {"0111", "0110", "0010", "0000", "1111", "1000", "1011", "0000", "1010", "1010", "1110", "0011", "0011", "0010", "1001", "1011", "0001", "0110", "1010", "0101"},
    {"0110", "1110", "1000", "1100", "1010", "0001", "1111", "1100", "0000", "0010", "0011", "0110", "0000", "1110", "0000", "1000", "1111", "0011", "0001", "1101"},
    {"0111", "0011", "0000", "0011", "1111", "0100", "1011", "0011", "1100", "0011", "0111", "0011", "0110", "1001", "1100", "0111", "0000", "1001", "0011", "1111"},
    {"0101", "1110", "0001", "1010", "1101", "0001", "0001", "1010", "1000", "1011", "0110", "1000", "0011", "1010", "0100", "0001", "0000", "1001", "1001", "1111"},
    {"1100", "0010", "1000", "1000", "0001", "1101", "1010", "1011", "1010", "0110", "0011", "1000", "0000", "1111", "1000", "0011", "1011", "1011", "0111", "1101"},
    {"1100", "1110", "0011", "0110", "1100", "0100", "1110", "0010", "0000", "0011", "0110", "1100", "1001", "0001", "0111", "0011", "0000", "0001", "0111", "1101"},
    {"1110", "1011", "1011", "0000", "0110", "1101", "1001", "0001", "0100", "0101", "1111", "1101", "0000", "1010", "0110", "0101", "0001", "0011", "0111", "1011"},
    {"0110", "1110", "1101", "1100", "0010", "1000", "0010", "0110", "1000", "0110", "0001", "1100", "0001", "0111", "1010", "0110", "0000", "1011", "0110", "0101"},
    {"0111", "0101", "0100", "0110", "0001", "1000", "1010", "1001", "0110", "1000", "0110", "1011", "1100", "0011", "1110", "1001", "0100", "0100", "0110", "0101"},
    {"1110", "1100", "1110", "0010", "0111", "0100", "1100", "0100", "1101", "1100", "0110", "0101", "1110", "1001", "0111", "0110", "0011", "1011", "1111", "1011"},
    {"1111", "0101", "0010", "0101", "0110", "1000", "1100", "1011", "1010", "0001", "1110", "1101", "0100", "1010", "1000", "0000", "1011", "0111", "0010", "0111"},
    {"0111", "1111", "1001", "0100", "0101", "0101", "1010", "1100", "1101", "0101", "0011", "0111", "0011", "0000", "1101", "0010", "0101", "1010", "0100", "1111"},
    {"1111", "1010", "0000", "0110", "1111", "1000", "1010", "0100", "1110", "0100", "1110", "0110", "0101", "1111", "1010", "1100", "0001", "0011", "0101", "0001"},
    {"1101", "1111", "1101", "1110", "0011", "0001", "0101", "1001", "0101", "0101", "1000", "1111", "0111", "0100", "1101", "1010", "0001", "0111", "0001", "1111"},
    {"0110", "0001", "1100", "0110", "0110", "0000", "1110", "1011", "1001", "1100", "0100", "1000", "0011", "0010", "0111", "0100", "0100", "0101", "1011", "1011"},
    {"0110", "1011", "1101", "0010", "1111", "1101", "1010", "1000", "1000", "1111", "1111", "1011", "0101", "0001", "1101", "1010", "0101", "1011", "0100", "1111"},
    {"1100", "1001", "1011", "1010", "1101", "0111", "0100", "0110", "0110", "1100", "1110", "1101", "1110", "0001", "0100", "0001", "0001", "0100", "0111", "1001"},
    {"1110", "1101", "1100", "0110", "0100", "1101", "1001", "0110", "1011", "0001", "0100", "0011", "0110", "1111", "1101", "0110", "1100", "1011", "1100", "0011"},
    {"0111", "1110", "1110", "0110", "0011", "0111", "0011", "1011", "0110", "0010", "1011", "1011", "0010", "1111", "0111", "0110", "1011", "0010", "0010", "0111"}
    };

vector<vector<string>> ExampleMaze2 = {
     {"1100", "1010", "1010", "1010", "1011", "1100", "1001", "1100", "1010", "1010", "1010", "1001", "1100", "1010", "1001", "1100", "1000", "1010", "1001", "1100", "1010", "1010", "1001", "1101", "1100", "1000", "1010", "1000", "1010", "1000", "1001", "1110", "1001", "1101", "1100", "1000", "1010", "1000", "1000", "1010", "1000", "1001", "1110", "1001", "1100", "1001", "1100", "1010", "1000", "1010", "1010", "1010", "1010", "1010", "1000", "1010", "1001", "1100", "1010", "1000", "1010", "1010", "1010", "1010", "1010", "1000", "1010", "1001", "1101", "1100", "1010", "1010", "1010", "1011", "1100", "1000", "1010", "1001", "1101", "1100", "1010", "1000", "1010", "1010", "1000", "1001", "1110", "1001", "1100", "1000", "1001", "1100", "1010", "1010", "1010", "1010", "1010", "1010", "1000", "1010", "1011", "1100", "1001", "1100", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1000", "1001", "1100", "1000", "1001", "1110", "1010", "1001", "1100", "1010", "1010", "1000", "1010", "1001", "1100", "1010", "1010", "1010", "1001", "1101", "1100", "1000", "1010", "1001", "1100", "1011", "1100", "1000", "1010", "1010", "1010", "1001", "1101", "1100", "1000", "1010", "1000", "1010", "1001", "1100", "1010", "1010", "1001", "1110", "1010", "1000", "1010", "1010", "1001", "1100", "1010", "1010", "1000", "1011", "1100", "1010", "1001", "1100", "1001", "1100", "1010", "1010", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1001", "1101", "1100", "1010", "1010", "1000", "1010", "1010", "1010", "1010", "1010", "1001", "1100", "1001", "1100", "1010", "1010", "1000", "1000", "1001", "1110", "1001", "1100", "1000", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1010", "1010", "1010", "1010", "1010", "1010", "1010", "1010", "1011", "1100", "1010", "1000", "1001", "1100", "1010", "1010", "1000", "1001", "1100", "1001", "1110", "1001", "1100", "1010", "1010", "1010", "1000", "1010", "1010", "1000", "1001", "1100", "1010", "1010", "1001", "1100", "1001", "1100", "1000", "1001", "1100", "1010", "1000", "1000", "1010", "1010", "1000", "1001", "1110", "1010", "1001", "1100", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1001", "1100", "1000", "1011", "1100", "1010", "1000", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1010", "1001", "1100", "1010", "1001", "1101", "1100", "1010", "1010", "1000", "1011", "1100", "1010", "1010", "1000", "1011", "1100", "1000", "1011", "1100", "1010", "1010", "1010", "1010", "1010", "1010", "1001", "1100", "1010", "1001", "1100", "1010", "1010", "1000", "1011", "1100", "1010", "1010", "1000", "1010", "1010", "1010", "1001", "1100", "1001", "1100", "1000", "1010", "1010", "1001", "1101", "1100", "1011", "1100", "1001", "1110", "1010", "1000", "1001", "1110", "1001", "1100", "1010", "1010", "1010", "1010", "1010", "1001", "1100", "1010", "1011", "1100", "1001", "1110", "1010", "1010", "1001", "1100", "1000", "1011", "1100", "1010", "1010", "1000", "1011", "1100", "1010", "1010", "1010", "1010", "1010", "1001", "1110", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1010", "1000", "1011", "1100", "1010", "1010", "1010", "1010", "1000", "1001", "1100", "1010", "1000", "1010", "1000", "1011", "1100", "1001", "1100", "1010", "1010", "1010", "1000", "1010", "1010", "1010", "1001", "1100", "1010", "1000", "1010", "1011", "1100", "1010", "1001", "1110", "1000", "1011", "1100", "1001", "1100", "1001", "1100", "1010", "1010", "1001", "1100", "1010", "1010", "1010", "1010", "1010", "1010", "1010", "1010", "1001", "1100", "1010", "1000", "1010", "1001", "1100", "1010", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1010", "1010", "1010", "1001", "1110", "1001", "1110", "1001", "1110", "1001", "1100", "1010", "1010", "1010", "1000", "1010", "1010", "1010", "1010", "1001", "1100", "1010", "1010", "1010", "1010", "1000", "1010", "1010", "1010", "1000", "1001", "1100", "1001", "1100", "1010", "1001", "1100", "1010", "1010", "1000", "1010", "1010", "1010", "1010", "1010", "1010", "1010", "1001", "1110", "1001", "1100", "1010", "1001", "1101", "1100", "1001", "1100", "1010", "1001", "1100", "1001", "1110", "1010", "1010", "1001", "1100", "1010", "1010", "1011", "1100", "1010", "1010", "1010", "1001", "1100", "1001", "1110", "1010", "1001", "1100", "1010", "1001", "1100", "1010", "1010", "1010", "1000", "1000", "1001", "1100", "1010", "1010", "1010", "1001", "1100", "1001"},
     //..................... * 549

    };


vector<string> DrawMaze(vector<vector<string>> Maze, int StartX, int StartY, int FinishX, int FinishY)
{

    vector<string> MazePath;

    int Rows = Maze.size();
    int Columns = Maze[0].size();

    for (int i = 0; i < Rows; ++i)
    {
        for (int j = 0; j < 3; j = ++j)
        {
            string PrintLayers = "";

            for (int k = 0; k < Columns; k = ++k)
            {

                bool CheckStartFinish = false;

                if (((StartX == k) && (StartY == i)) || ((FinishX == k + 1) && (FinishY == i + 1)))
                {
                    CheckStartFinish = true;
                }

                if (j == 0)
                {
                    if (Maze[i][k][j] == '0')
                    {
                        PrintLayers = PrintLayers + "+  ";
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        PrintLayers = PrintLayers + "+--";
                    }
                }
                else if (j == 1)
                {
                    if (Maze[i][k][j] == '0')
                    {
                        if (CheckStartFinish == false)
                        {
                            PrintLayers = PrintLayers + "   ";
                        }
                        else if (CheckStartFinish == true)
                        {
                            if (StartX == k)
                            {
                                PrintLayers = PrintLayers + " ST";
                            }
                            if (FinishX == k + 1)
                            {
                                PrintLayers = PrintLayers + " FN";
                            }
                        }
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        if (CheckStartFinish == false)
                        {
                            PrintLayers = PrintLayers + "|  ";
                        }
                        if (CheckStartFinish == true)
                        {
                            if (StartX == k)
                            {
                                PrintLayers = PrintLayers + "|ST";
                            }
                            if (FinishX == k + 1)
                            {
                                PrintLayers = PrintLayers + "|FN";
                            }
                        }
                    }
                }

                if ((j == 0) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + "+";
                }
                else if ((j == 1) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + "|";
                }
                if ((i + 1 == Rows) && (j == 2))
                {
                    if (Maze[i][k][j] == '0')
                    {
                        PrintLayers = PrintLayers + "+  ";
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        PrintLayers = PrintLayers + "+--";
                    }
                }
                if ((i + 1 == Rows) && (j == 2) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + "+";
                }

            }

            if (!PrintLayers.empty())
            {
                cout << PrintLayers << endl;
                MazePath.push_back(PrintLayers);
            }
        }
    }
    return MazePath;
}

vector<string> ShowPath(vector<vector<string>> Maze, int StartX, int StartY, int FinishX, int FinishY)
{
    vector<string> MazePath;

    int Rows = Maze.size();
    int Columns = Maze[0].size();

    for (int i = 0; i < Rows; ++i) 
    {
        for (int j = 0; j < 2; j = ++j) 
        {
            string PrintLayers;

            for (int k = 0; k < Columns; k = ++k)
            {

                bool CheckStartFinish = false;

                if (((StartX == k) && (StartY == i)) || ((FinishX == k + 1) && (FinishY == i + 1)))
                {
                    CheckStartFinish = true;
                }

                if (j == 0) 
                {
                    if (Maze[i][k][j] == '0') 
                    {
                        PrintLayers = PrintLayers + " XX";
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        PrintLayers = PrintLayers + "   ";
                    }
                }
                else if (j == 1) 
                {
                    if (Maze[i][k][j] == '0')
                    {
                        if (CheckStartFinish == false) 
                        {
                            PrintLayers = PrintLayers + "XXX";
                        }
                        else if (CheckStartFinish == true)
                        {
                            if (StartX == k) 
                            {
                                PrintLayers = PrintLayers + "XST";
                            }
                            if (FinishX == k + 1) 
                            {
                                PrintLayers = PrintLayers + "XFN";
                            }
                        }
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        if (CheckStartFinish == false) 
                        {
                            PrintLayers = PrintLayers + " XX";
                        }
                        if (CheckStartFinish == true) 
                        {
                            if (StartX == k) 
                            {
                                PrintLayers = PrintLayers + " ST";
                            }
                            if (FinishX == k + 1) 
                            {
                                PrintLayers = PrintLayers + " FN";
                            }
                        }
                    }
                }

                if ((j == 0) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + " ";
                }
                else if ((j == 1) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + " ";
                }
                if ((i + 1 == Rows) && (j == 2))
                {
                    if (Maze[i][k][j] == '0')
                    {
                        PrintLayers = PrintLayers + " XX";
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        PrintLayers = PrintLayers + "   ";
                    }
                }
                if ((i + 1 == Rows) && (j == 3) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + " ";
                }

            }

            if (!PrintLayers.empty())
            {
                //cout << PrintLayers << endl;
                MazePath.push_back(PrintLayers);
            }
        }
    }
    return MazePath;
}

vector<vector<int>> FindPaths(vector<string> MazePath)
{
    int xPos = 0;
    int yPos = 0;

    int TrueXPos = (1 + (xPos * 3));
    int TrueYPos = (1 + (yPos * 2));

    bool N = true;
    bool E = true;
    bool S = true;
    bool W = true;

    vector<string> Path;
    string Direction = "N";
    Path.push_back(Direction);
    int i = 0;

    vector<string> DirectionOrder = { "N", "E", "S", "W" };
    string TempDirection;
    string DirectFrom = "N";
    vector<vector<int>> RouteCoords = { {0,0} };

    while (((N == true) || (E == true) || (S == true) || (W == true)) && (i < 60)) 
    {
        vector<string> Possibilities = {};
        N = false;
        E = false;
        S = false;
        W = false;

        if ((TrueYPos - 1 > 0) && (TrueYPos - 1 < MazePath.size()) && (TrueXPos > 0) && (TrueXPos < MazePath[0].size())) 
        {
            if (MazePath[TrueYPos - 1][TrueXPos] != ' ')
            {
                N = true;
                Possibilities.push_back("N");
            }
        }

        if ((TrueYPos > 0) && (TrueYPos < MazePath.size()) && (TrueXPos +2 > 0) && (TrueXPos + 2 < MazePath[0].size()))
        {
            if (MazePath[TrueYPos][TrueXPos + 2] != ' ')
            {
                E = true;
                Possibilities.push_back("E");
            }
        }

        if ((TrueYPos + 1 > 0) && (TrueYPos + 1 < MazePath.size()) && (TrueXPos > 0) && (TrueXPos < MazePath[0].size()))
        {
            if (MazePath[TrueYPos + 1][TrueXPos] != ' ')
            {
                S = true;
                Possibilities.push_back("S");
            }
        }

        if ((TrueYPos > 0) && (TrueYPos < MazePath.size()) && (TrueXPos - 1 > 0) && (TrueXPos - 1 < MazePath[0].size()))
        {
            if (MazePath[TrueYPos][TrueXPos - 1] != ' ')
            {
                W = true;
                Possibilities.push_back("W");
            }
        }



        if (MazePath[TrueYPos][TrueXPos] == 'F')
        {
            cout << "Finished" << endl;
            return RouteCoords;
        }
        if (MazePath[TrueYPos-1][TrueXPos] == 'F')
        {
            cout << "Finished" << endl;
            return RouteCoords;
        }
        if (MazePath[TrueYPos][TrueXPos+2] == 'F')
        {
            cout << "Finished" << endl;
            return RouteCoords;
        }
        if (MazePath[TrueYPos+1][TrueXPos] == 'F')
        {
            cout << "Finished" << endl;
            return RouteCoords;
        }
        if (MazePath[TrueYPos][TrueXPos-1] == 'F')
        {
            cout << "Finished" << endl;
            return RouteCoords;
        }

        for (int z = 0; z < 4; ++z)
        {
            //cout << "Checking: " << DirectionOrder[z] << "    ";
            //cout << "N: " << N << " E: " << E << " S: " << S << " W: " << W << endl;

            if ((N == true) && (DirectionOrder[z] == "N"))
            {
                cout << "Move North" << endl;
                Direction = "N";
                yPos += -1;
                DirectFrom = "S";
                cout << "X: " << xPos << " Y: " << yPos << endl;
                break;
            }
            if ((S == true) && (DirectionOrder[z] == "S"))
            {
                cout << "Move South" << endl;
                Direction = "S";
                yPos += 1;
                DirectFrom = "N";
                cout << "X: " << xPos << " Y: " << yPos << endl;
                break;
            }
            if ((W == true) && (DirectionOrder[z] == "W"))
            {
                cout << "Move West" << endl;
                Direction = "W";
                xPos += -1;
                DirectFrom = "E";
                cout << "X: " << xPos << " Y: " << yPos << endl;
                break;
            }
            if ((E == true) && (DirectionOrder[z] == "E"))
            {
                cout << "Move East" << endl;
                Direction = "E";
                xPos += 1;
                DirectFrom = "W";
                cout << "X: " << xPos << " Y: " << yPos << endl;
                break;
            }
        }

        Path.push_back(Direction);
        auto itr = std::find(DirectionOrder.begin(), DirectionOrder.end(), DirectFrom);
        if (itr != DirectionOrder.end()) DirectionOrder.erase(itr);
        DirectionOrder.push_back(DirectFrom);

        RouteCoords.push_back({xPos,yPos});
        TrueXPos = (1 + (xPos * 3));
        TrueYPos = (1 + (yPos * 2));
        i += 1;
    }

    for (int b = 0; b < RouteCoords.size(); ++b) 
    {
        cout << "{";

        for (int c = 0; c < RouteCoords[b].size(); ++c) 
        {
            cout << RouteCoords[b][c] << ",";
        }
        cout << "},";
    }
    cout << endl;

    return RouteCoords;
}

void  MapRoute(vector<vector<string>> Maze, int StartX, int StartY, int FinishX, int FinishY, vector<vector<int>> RouteCoords)
{

    vector<string> MazePath;

    int Rows = Maze.size();
    int Columns = Maze[0].size();
    bool AddRoute = false;

    for (int i = 0; i < Rows; ++i)
    {
        for (int j = 0; j < 3; j = ++j)
        {
            string PrintLayers = "";

            for (int k = 0; k < Columns; k = ++k)
            {
                AddRoute = false;
                for (int c = 0; c < RouteCoords.size(); ++c) 
                {
                    if ((RouteCoords[c][0] == k) && (RouteCoords[c][1] == i)) 
                    {
                        AddRoute = true;
                    }
                }

                bool CheckStartFinish = false;

                if (((StartX == k) && (StartY == i)) || ((FinishX == k + 1) && (FinishY == i + 1)))
                {
                    CheckStartFinish = true;
                }

                if (j == 0)
                {
                    if (Maze[i][k][j] == '0')
                    {
                        PrintLayers = PrintLayers + "+  ";
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        PrintLayers = PrintLayers + "+--";
                    }
                }
                else if (j == 1)
                {
                    if (Maze[i][k][j] == '0')
                    {
                        if (CheckStartFinish == false)
                        {
                            if (AddRoute == true) 
                            {
                                PrintLayers = PrintLayers + " XX";
                            }
                            else
                            {
                                PrintLayers = PrintLayers + "   ";
                            }
                        }
                        else if (CheckStartFinish == true)
                        {
                            if (StartX == k)
                            {
                                PrintLayers = PrintLayers + " ST";
                            }
                            if (FinishX == k + 1)
                            {
                                PrintLayers = PrintLayers + " FN";
                            }
                        }
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        if (CheckStartFinish == false)
                        {
                            if (AddRoute == true)
                            {
                                PrintLayers = PrintLayers + "|XX";
                            }
                            else
                            {
                                PrintLayers = PrintLayers + "|  ";
                            }
                        }
                        if (CheckStartFinish == true)
                        {
                            if (StartX == k)
                            {
                                PrintLayers = PrintLayers + "|ST";
                            }
                            if (FinishX == k + 1)
                            {
                                PrintLayers = PrintLayers + "|FN";
                            }
                        }
                    }
                }

                if ((j == 0) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + "+";
                }
                else if ((j == 1) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + "|";
                }
                if ((i + 1 == Rows) && (j == 2))
                {
                    if (Maze[i][k][j] == '0')
                    {
                        PrintLayers = PrintLayers + "+  ";
                    }
                    else if (Maze[i][k][j] == '1')
                    {
                        PrintLayers = PrintLayers + "+--";
                    }
                }
                if ((i + 1 == Rows) && (j == 2) && (k + 1 == Maze.size()))
                {
                    PrintLayers = PrintLayers + "+";
                }

            }

            if (!PrintLayers.empty())
            {
                cout << PrintLayers << endl;
                MazePath.push_back(PrintLayers);
            }
        }
    }
    return;
}


int main()
{
    //cout << ExampleMaze[0][0][0] << endl;
    //DrawMaze(ExampleMaze, 0, 0, 20, 20);
    cout << endl;
    MapRoute(ExampleMaze2,0,0,20,20,FindPaths(ShowPath(ExampleMaze2, 0, 0, 20, 20)));

}

0 个答案:

没有答案