【set】【HDU 5818】 Joint Stacks

 

题目链接:

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

 

题解:

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

 

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<set>
 7 #include<iterator>
 8 using namespace std;
 9 typedef struct point{
10     int x, y;
11     bool operator < (const point& p) const{
12         return x > p.x;
13     }
14     bool operator >(const point& p) const{
15         return p < *this;
16     }
17 }p;
18 
19 char str[200], ins[100];
20 set<p> a, b, c;
21 
22 int main(){
23     //freopen("in.txt", "r", stdin);
24     //freopen("out.txt", "w", stdout);
25     int N;
26     int Case = 0;
27     while(~scanf("%d", &N) && N!=0){
28         getchar();
29         Case++;
30         printf("Case #%d:\n", Case);
31         a.clear();
32         b.clear();
33         c.clear();
34         char pos;
35         int v;
36         int num = 1;
37         while(N--){
38             gets(str);
39             if(str[1] == 'u'){
40                 sscanf(str, "%s %c %d", ins, &pos, &v);
41                 p tmp;
42                 tmp.x = num, tmp.y = v;
43                 if(pos == 'A') a.insert(tmp);
44                 else b.insert(tmp);
45                 num++;
46             }
47             else if(str[1] == 'o'){
48                 set<p>::iterator it;
49                 if(str[4] == 'A'){
50                     if(a.size()!=0){
51                         it = a.begin();
52                         printf("%d\n", (*it).y);
53                         a.erase(it);
54                     }
55                     else{
56                         it = c.begin();
57                         printf("%d\n", (*it).y);
58                         c.erase(it);
59                     }
60                 }
61                 else{
62                     if(b.size()!=0){
63                         it = b.begin();
64                         printf("%d\n", (*it).y);
65                         b.erase(it);
66                     }
67                     else{
68                         it = c.begin();
69                         printf("%d\n", (*it).y);
70                         c.erase(it);
71                     }
72                 }
73             }
74             else{
75                 set<p>::iterator it;
76                 if(a.size()!=0){
77                     for(it=a.begin(); it!=a.end(); it++){
78                         p tmp = (*it);
79                         c.insert(tmp);
80                     }
81                     a.clear();
82                 }
83                 if(b.size()!=0){
84                     for(it=b.begin(); it!=b.end(); it++){
85                         p tmp = (*it);
86                         c.insert(tmp);
87                     }
88                     b.clear();
89                 }
90             }
91         }
92     }
93 
94     return 0;
95 }

 

转载于:https://www.cnblogs.com/miaowTracy/p/5755585.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值