问题描述
- 一个acm题中出现的迭代器相关错误求解
-
#include
#include
#includeusing namespace std;
int main()
{
int n,a,b;
int count1 = 0,count2 = 0;
map p;
vector xm;
vector xy;
while(scanf("%d",&n) != EOF)
{
for(int i = 0;i < n;++i)
{
scanf("%d%d",&a,&b);
p[a] = b;
}
vector::iterator iter1;
xm.push_back(p[1]);
iter1 = xm.begin();
while(p.count(*iter1))
{
xm.push_back(p[*iter1]);
++iter1;
}
vector::iterator iter2;
xy.push_back(p[2]);
iter2 = xy.begin();
while(p.count(*iter2))
{
xy.push_back(p[*iter2]);
++iter2;
}
iter1 = xm.begin();
iter2 = xy.begin();
int flag = 0;
for(;iter1 != xm.end();++iter1,++count1)
{
if(flag)
break;
for(;iter2 != xy.end();++iter2,++count2)
{
if(*iter1 == *iter2)
{
if(count1 == count2)
{
printf("%sn","You are my brother");
flag = 1;
}
else if(count1 > count2)
{
printf("%sn","You are my elder");
flag = 1;
}
else
{
printf("%sn","You are my younger");
flag = 1;
}
}
}
count2 = 0;
}
}return 0;
}
大家好,我想问一下为什么在我执行代码执行到++iter1的时候,总是出现Debug Assertion Failed的错误,出现的是对话框,提示是:Expression:("this->_Has_container()",()),这事什么原因了?该如何解决呢?