您的位置:首页 > 产品设计 > UI/UE

poj 3481 Double Queue

2016-07-16 23:59 363 查看
删除map中元素再返回it->second导致1WA

#include <cstdio>
#include <map>
using namespace std;
int op, K, P;
map<int, int> mp;
int gethigh() {
if (!mp.size())
return 0;
map<int, int>::iterator it=mp.end();
it--;
int res=it->second;
mp.erase(it->first);
return res;
}
int getlow() {
if (!mp.size())
return 0;
map<int, int>::iterator it=mp.begin();
int res=it->second;
mp.erase(it->first);
return res;
}
int main()
{
//freopen("in.txt", "r", stdin);
while (~scanf("%d", &op)&&op!=0) {
if (op==2) {
printf("%d\n", gethigh());
} else if (op==3) {
printf("%d\n", getlow());
} else {
scanf("%d%d", &K, &P);
mp[P]=K;
}
}
return 0;
}


故用res先存,删除后返回res
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: