您的位置:首页 > 其它

【set】【HDU 5818】 Joint Stacks

2016-08-10 09:59 330 查看
题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5818

题解:

http://bestcoder.hdu.edu.cn/blog/2016-multi-university-training-contest-7-solutions-by-sysu/

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<iterator>
using namespace std;
typedef struct point{
int x, y;
bool operator < (const point& p) const{
return x > p.x;
}
bool operator >(const point& p) const{
return p < *this;
}
}p;

char str[200], ins[100];
set<p> a, b, c;

int main(){
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int N;
int Case = 0;
while(~scanf("%d", &N) && N!=0){
getchar();
Case++;
printf("Case #%d:\n", Case);
a.clear();
b.clear();
c.clear();
char pos;
int v;
int num = 1;
while(N--){
gets(str);
if(str[1] == 'u'){
sscanf(str, "%s %c %d", ins, &pos, &v);
p tmp;
tmp.x = num, tmp.y = v;
if(pos == 'A') a.insert(tmp);
else b.insert(tmp);
num++;
}
else if(str[1] == 'o'){
set<p>::iterator it;
if(str[4] == 'A'){
if(a.size()!=0){
it = a.begin();
printf("%d\n", (*it).y);
a.erase(it);
}
else{
it = c.begin();
printf("%d\n", (*it).y);
c.erase(it);
}
}
else{
if(b.size()!=0){
it = b.begin();
printf("%d\n", (*it).y);
b.erase(it);
}
else{
it = c.begin();
printf("%d\n", (*it).y);
c.erase(it);
}
}
}
else{
set<p>::iterator it;
if(a.size()!=0){
for(it=a.begin(); it!=a.end(); it++){
p tmp = (*it);
c.insert(tmp);
}
a.clear();
}
if(b.size()!=0){
for(it=b.begin(); it!=b.end(); it++){
p tmp = (*it);
c.insert(tmp);
}
b.clear();
}
}
}
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: