C++ 运行时出现SIGABRT错误(c+;+;)
这是来自spoj的摩天大楼楼层问题。当我运行代码时,我得到了SIGABRT。问题的链接是。当我在我的电脑上运行此代码时,它运行时没有任何错误,但spoj的在线判断显示SIGABRT错误C++ 运行时出现SIGABRT错误(c+;+;),c++,runtime-error,sigabrt,C++,Runtime Error,Sigabrt,这是来自spoj的摩天大楼楼层问题。当我运行代码时,我得到了SIGABRT。问题的链接是。当我在我的电脑上运行此代码时,它运行时没有任何错误,但spoj的在线判断显示SIGABRT错误 #include <iostream> #include <vector> using namespace std; struct floor { unsigned int floornum; bool calldone; vector <floor*>
#include <iostream>
#include <vector>
using namespace std;
struct floor
{
unsigned int floornum;
bool calldone;
vector <floor*> connection;
floor()
{
floornum=0;
calldone=0;
}
};
struct elevator
{
unsigned int x,y;
elevator()
{
x=y=0;
}
};
struct skyscrapper
{
unsigned int f,e,a,b;
vector <elevator> ele;
vector <floor*> flooraddress; //this is a spoj problem
void read()
{
cin>>f>>e>>a>>b;
elevator *temp;
for(unsigned int i=0;i<e;i++)
{
temp=new elevator;
cin>>(*temp).x>>(*temp).y;
ele.push_back(*temp);
}
for (unsigned int i=0;i<f;i++)
{
floor* tempp=new floor;
(*tempp).floornum=i;
flooraddress.push_back(tempp);
}
}
void allotaddress()
{
unsigned int j,k;
for(unsigned int i=0;i<ele.size();i++)
{
j=ele[i].y;
k=ele[i].x;
while(j<f)
{
if(j!=ele[i].y)
{
(*(flooraddress[j])).connection.push_back(flooraddress[j-k]);
(*(flooraddress[j-k])).connection.push_back(flooraddress[j]);
}
j=j+k;
}
}
}
};
bool flag;
bool traverse(floor* m,int destination)
{
if((*m).calldone==1)
{
return 0;
}
(*m).calldone=1;
if((*m).floornum==destination)
return 1;
if((*m).connection.empty())
return 0;
for(int i=0;i<(*m).connection.size();i++)
{
flag=traverse(((*m).connection[i]),destination);
if(flag==1)
return flag;
}
return 0;
}
int main()
{
int n;
cin>>n;
skyscrapper iit[n];
bool ans[n];
for(int i=0;i<n;i++)
{
iit[i].read();
iit[i].allotaddress();
ans[i]=traverse(iit[i].flooraddress[iit[i].a],iit[i].b);
}
for(int i=0;i<n;i++)
{
if(ans[i]==1)
cout<<"It is possible to move the furniture."<<endl;
else
cout<<"The furniture cannot be moved."<<endl;
}
return 0;
}
#包括
#包括
使用名称空间std;
结构层
{
无符号整数楼层;
布尔·卡尔顿;
矢量连接;
发言权()
{
地板厚度=0;
calldone=0;
}
};
结构升降机
{
无符号整数x,y;
电梯()
{
x=y=0;
}
};
结构SkyScraster
{
无符号整数f,e,a,b;
矢量元素;
vector flooraddress;//这是一个spoj问题
无效读取()
{
cin>>f>>e>>a>>b;
电梯*温度;
对于(无符号整数i=0;i>(*temp.x>>(*temp.y);
电气推回(*温度);
}
对于(unsigned int i=0;i您需要进行错误检查。如果new
返回nullptr
,您很乐意取消对它的引用。您在read()中存在内存泄漏new如何返回nullptr?@user2684957temp=new lifter;
在那里。你需要经常检查你的输入在阅读后是否成功。快速查看表达式,它似乎有一些有趣的值,但它被用作向量的索引。你似乎泄漏了所有内存:你分配内存,但你从来没有删除/<代码>它。你应该去掉所有指针和所有<代码>新< /Calp> S:C++不是java或C!你可以创建值。