queue

本文提供了一段关于BNUOJ竞赛中特定题目(链接:https://www.bnuoj.com/v3/contest_show.php?cid=9057#problem/K)的C++代码解析,该代码实现了一个涉及字符串操作、队列使用及哈希映射的算法问题解决方案。通过实例展示了如何处理数据输入输出、字符串与整数的映射关系、队列操作以及解决特定问题的逻辑。

题目连接:https://www.bnuoj.com/v3/contest_show.php?cid=9057#problem/K

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<queue>
 4 #include<cctype>
 5 #include<algorithm>
 6 #include<map>
 7 #include<string>
 8 #include<iostream>
 9 using namespace std;
10 int t,n;
11 map<string, int> p;
12 string c,s;
13 int vis[100020];
14 int main()
15 {
16     scanf("%d",&t);
17     while(t--)
18     {
19         int cnt=0;
20         int ans=0;
21         queue<int> q;
22         while(!q.empty()) q.pop();
23         scanf("%d",&n);
24         p.clear();
25         memset(vis,0,sizeof(vis));
26         for(int i=0;i<n;i++)
27         {
28             cin>>c>>s;
29 
30             if(c[0]=='i')
31             {
32                 p[s]=cnt++;
33                 q.push(p[s]);
34             }
35             else
36             {
37                 int x=q.front();
38                 while(vis[x]) {q.pop();x=q.front();}
39                 if(x==p[s]) q.pop();
40                 else {
41                 vis[p[s]]=1;
42                 ans++;
43                 }
44             }
45         }
46         cout<<n/2-ans<<endl;
47     }
48 }

 

转载于:https://www.cnblogs.com/yijiull/p/6753555.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值