听着夜曲逛威尼斯 2015-10-19 14:22 采纳率: 100%
浏览 1369
已采纳

C++ 迷宫问题,代码运行除了正确结果却提示出错

代码如下:

 #include<iostream>
using namespace std;

int main()
{
    //矩阵初始化
    int **migong;
    int h, w;
    int m, n;
    cout << "请输入迷宫高度h和迷宫宽度w:" << endl;
    cin >> h >> w;
    migong = new int *[h];
    for (int i = 0; i < h ; i++)
    {
        migong[i] = new int[w];
    }
    for (m = 0; m < h ; m++)
    {
        for (n = 0; n < w ; n++)
        {
            cin>>migong[m][n] ;
        }
    }
    //输出矩阵
    for (m = 0; m < h; m++)
    {
        for (n = 0; n < w; n++)
        {
            cout << migong[m][n] << "    ";
        }
        cout << endl;
    }
    int temp = 0;
    if (h >= w)
        temp = h;
    else
        temp = w;
    int *path_row = new int;//通行路径的行
    int *path_column = new int;//通行路径的列
    for (int i = 0; i < temp; i++)
        path_row[i] = path_column[i] = 0;
    int row = 0;
    int column = 0;
    int count = 0;
    do
    {
        column = 0;
        do
        {
            switch (migong[row][column])
            {
            case 3:
                cout << "入口坐标为:" << "(" << row << "," << column << ")" << endl;
            }
            switch (migong[row][column])
            {
            case 0:
                path_row[count] = row;
                path_column[count] = column;
                cout << "(" << row << "," << column << ")" << endl;
                count++;
                break;
            case 1:
                break;
            }
            switch (migong[row][column])
            {
            case 4:
                cout << "出口坐标为:" << "(" << row << "," << column << ")" << endl;
            }
            column += 1;
        } while (column < w);
        row += 1;
    }while (row < h);
    for (m = 0; m < h ; m++)
    {
        delete[] migong[m];
    }
    delete migong;
    delete path_row;
    delete path_column;
    system("pause");
    return 0;
}

麻烦各位大神看看是哪儿出错了

  • 写回答

1条回答 默认 最新

  • threenewbee 2015-10-19 15:12
    关注

    如果结果正确却丢出异常,显然是delete的问题。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 无网格伽辽金方法研究裂纹扩展的程序
  • ¥15 如何用数码管显示学号(相关搜索:单片机)
  • ¥15 错误于library(org.Hs.eg.db): 不存在叫‘org.Hs.eg.db’这个名称的程序包,如何解决?
  • ¥60 求一个图片处理程序,要求将图像大小跟现实生活中的大小按比例联系起来的
  • ¥50 求一位精通京东相关开发的专家
  • ¥100 求懂行的大ge给小di解答下!
  • ¥15 pcl运行在qt msvc2019环境运行效率低于visual studio 2019
  • ¥15 MAUI,Zxing扫码,华为手机没反应。可提高悬赏
  • ¥15 python运行报错 ModuleNotFoundError: No module named 'torch'
  • ¥100 华为手机私有App后台保活