我是靠谱客的博主 奋斗钢笔,这篇文章主要介绍UVA540解题报告,现在分享给大家,希望可以做个参考。

挺简单的一道模拟题,用来做STL或数据结构的练习题还是不错的。注意的是这次用到了不止一个队列而是1000个,还有就是同一个队的要编号

附上AC代码 time 30ms

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<cstdio> #include<map> #include<queue> using namespace std; const int maxn=1000+10; char order[10]; int main() { int num,ans,test=1; while(scanf("%d",&num)==1 && num) { int k; ans=0; map<int,int> m; queue<int> a; queue<int> b[maxn]; printf("Scenario #%dn",test++); for(int i=0;i<num;i++) { scanf("%d",&k); while(k--) { int x; scanf("%d",&x); m[x]=ans; } ans++; } while(scanf("%s",order)==1 && order[0]!='S') { getchar(); if(order[0]=='E') { int x; scanf("%d",&x); int pos=m[x]; if(b[pos].empty()) a.push(pos); b[pos].push(x); } else if(order[0]=='D') { int pos=a.front(); printf("%dn",b[pos].front()); b[pos].pop(); if(b[pos].empty()) a.pop(); } } printf("n"); } return 0; }

以下是错误代码,亲爱的小伙伴们,你们能找到错误吗,博主我可是找到了呢

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<cstdio> #include<map> #include<queue> using namespace std; const int maxn=1000+10; char order[10]; map<int,int> m; queue<int> a; queue<int> b[maxn]; int main() { int num,ans,test=1; while(scanf("%d",&num)==1 && num) { int k; ans=0; printf("Scenario #%dn",test++); for(int i=0;i<num;i++) { scanf("%d",&k); while(k--) { int x; scanf("%d",&x); m[x]=ans; } ans++; } while(scanf("%s",order)==1 && order[0]!='S') { getchar(); if(order[0]=='E') { int x; scanf("%d",&x); int pos=m[x]; if(b[pos].empty()) a.push(pos); b[pos].push(x); } else if(order[0]=='D') { int pos=a.front(); printf("%dn",b[pos].front()); b[pos].pop(); if(b[pos].empty()) a.pop(); } } printf("n"); } return 0; }
全局变量的使用造成了初始化问题,但在主函数里在定义变量就可以很好地解决这一问题

最后

以上就是奋斗钢笔最近收集整理的关于UVA540解题报告的全部内容,更多相关UVA540解题报告内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部