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
#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
相关文章推荐
- Leetcode题解 303. Range Sum Query - Immutable
- [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
- Leetcode题解 374. Guess Number Higher or Lower
- 虚幻4过场动画编辑器Sequencer脑图
- 虚幻4过场动画编辑器Sequencer脑图
- UVA 540 Team Queue
- Codeforces 689D Friends and Subsequences (RMQ+二分)
- StringBuffer、StringBuilder和BigDecimal
- HDU 5288 OO’s Sequence (from: 2015 Multi-University Training Contest 1)
- POJ3080 Blue Jeans
- UITableViewCell高度自适应探索--AutoLayout结合Frame
- LeetCode:Implement Queue using Stacks
- js中document.getElementById("id").value+1问题
- android产品研发(二十一)-->android中的UI优化
- 【一天一道LeetCode】#232. Implement Queue using Stacks
- 【一天一道LeetCode】#232. Implement Queue using Stacks
- JMenuBar,JMenu,JMenuItem的关系
- Build Slic3r on Windows // 如何在Windows上编译Slic3r
- UE4中使用数据表(Data Table)
- require.js的用法