#include<vector>
#include<string.h>
#include<sstream>
#include<map>
#include<windows.h>
#include"MyStack.h"
#include"DrawUtil.h"
#include"mapdata.h"
#include <iostream.h>
#define SLEEP_MS 1000
using namespace std;
string fromIntToString(int a)
{
string res;
stringstream ss;
ss << a;
ss>> res;
return res;
}
int sequence[4][2]=
{
{0,-1},{1,0},{0,1},{-1,0}
};
int main(int argc, char *argv[])
{
std::map<string,int*>hm;
MyStack<int*>stack;
int visited[MAP_SIZE][MAP_SIZE];
memset(visited,0,MAP_SIZE*MAP_SIZE*sizeof(int));
bool flag=true;
int start[4]={0,0,0,0};
stack.push(start);
int endCol;
int endRow;
while(flag)
{
int* currentEdge=stack.pop();
int tempTarget[2]={currentEdge[2],currentEdge[3]};
if(visited[tempTarget[1]][tempTarget[0]]==1)
{
continue;
}
visited[tempTarget[1]][tempTarget[0]]=1;
hm[fromIntToString(tempTarget[1])+":"+fromIntToString(tempTarget[0])]=
new int[2]{currentEdge[1],currentEdge[0]};
Sleep(SLEEP_MS);
if(mapStatus[tempTarget[1]][tempTarget[0]]==2)
{
endCol=tempTarget[0];
endRow=tempTarget[1];
break;
}
int currCol=tempTarget[0];
int currRow=tempTarget[1];
for(int k=0;k<4;k++)
{
int* rc=sequence[k];
int i=rc[1];
int j=rc[0];
if(currRow+i>=0&&currRow<MAP_SIZE&&currCol>=0&&currCol<MAP_SIZE&&mapStatus[currRow+i][currCol+j]!=0)
{
int* tempEdge=new int[4]
{
currCol,currRow,currCol+j,currRow+i
};
stack.push(tempEdge);
}
drawMap(mapStatus,visited,true);
}
MyStack<string> pathStr;
string currP=fromIntToString(endRow)+":"+fromIntToString(endCol);
pathStr.push(currP);
while(true)
{
int* tempP=hm[currP];
currP=fromIntToString(tempP[0])+":"+fromIntToString(tempP[1]);
if(mapStatus[tempP[0]][tempP[1]]==1)
{
mapStatus[tempP[0]][tempP[1]]=4;
}
pathStr.push(currP);
if(tempP[0]==0&&tempP[1]==0)
{
break;
}
}
cout<<"=========================================="<<endl;
int count=0;
while(!pathStr.isEmpty())
{
count++;
cout<<pathStr.pop()<<"->";
if(count==10);
{
count=0;
cout<<endl;
}
}
cout<<"Finish"<<endl;
cout<<"============================================"<<endl;
drawMap(mapStatus,visited,false);
return 0;
}}
图片这两处语法出错了还是什么 为何总是报括号前缺少分号呢?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2020-06-03 10:37关注
不支持这种初始化的形式
你就写
int * tempEdge = new int[4];
tempEdge[0] = currCol;
tempEdge[1] = currRow;
...本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用
悬赏问题
- ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
- ¥15 微信公众号自制会员卡没有收款渠道啊
- ¥15 stable diffusion
- ¥100 Jenkins自动化部署—悬赏100元
- ¥15 关于#python#的问题:求帮写python代码
- ¥20 MATLAB画图图形出现上下震荡的线条
- ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
- ¥15 perl MISA分析p3_in脚本出错
- ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
- ¥15 ubuntu虚拟机打包apk错误