Open Judge 3339 List

3339:List

总时间限制: 
4000ms

内存限制: 
65536kB
描述

写一个程序完成以下命令:
new id ——新建一个指定编号为id的序列(id<10000)
add id num——向编号为id的序列加入整数num
merge id1 id2——合并序列id1和id2中的数,并将id2清空
unique id——去掉序列id中重复的元素
out id ——从小到大输出编号为id的序列中的元素,以空格隔开

输入
第一行一个数n,表示有多少个命令( n<=200000)。以后n行每行一个命令。
输出
按题目要求输出。
样例输入
16
new 1
new 2
add 1 1
add 1 2
add 1 3
add 2 1
add 2 2
add 2 3
add 2 4
out 1
out 2
merge 1 2
out 1
out 2
unique 1
out 1
样例输出
1 2 3
1 2 3 4
1 1 2 2 3 3 4

1 2 3 4
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <list>
 5 #include <map>
 6 using namespace std;
 7
 8 map<int,list<int> > m;
 9
10 int n,x,y;
11 char op[10000];
12 int main(){
13     scanf("%d",&n);
14     while(n--){
15         scanf("%s",op);
16         if(strcmp(op,"new")==0){
17             scanf("%d",&x);
18             m.insert(map<int,list<int> >::value_type(x,list<int>()));
19         }
20         if(strcmp(op,"add")==0){
21             scanf("%d%d",&x,&y);
22             m[x].push_back(y);
23         }
24         if(strcmp(op,"merge")==0){
25             scanf("%d%d",&x,&y);
26             m[x].merge(m[y]);
27             //m[y].clear();
28         }
29         if(strcmp(op,"unique")==0){
30             scanf("%d",&x);
31             m[x].sort();
32             m[x].unique();
33         }
34         if(strcmp(op,"out")==0){
35             scanf("%d",&x);
36             m[x].sort();
37             list<int>::iterator it;
38             for(it=m[x].begin();it!=m[x].end();it++){
39                 printf("%d ",*it);
40             }
41             printf("\n");
42         }
43     }
44 }

既然还有list这STL,长见识了真是~~唉~~

时间: 2024-10-07 21:41:56

Open Judge 3339 List的相关文章

657. Judge Route Circle 判断线路成圆

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a characte

Special Judge Ⅱ

Problem Description Q:什么是 Special Judge,Special Judge 的题目有什么不同? A:一个题目可以接受多种正确答案,即有多组解的时候,题目就必须被 Special Judge.Special Judge 程序使用输入数据和一些其他信息来判答程序的输出,并将判答结果返回. NaYe 最近遇到了一个题,要求输出三个数,第三个数为前两个数的和,三个数都是素数,且前两个数小于 500000.他只需要输出任意一组符合要求的答案即认为是 Accepted.现在需

专题一、简单搜索 - Virtual Judge

很久以前刷完了Virtual Judge上的简单搜索专题,现总结如下: POJ 1321 由于题目的数据范围比较小,可以直接dfs暴力.读入时记录每个空位的位置,保存在pX[]以及pY[]数组中.暴力的时候统计当前处理第几个空格以及当前处理到了第几行即可. #include <iostream> #include <memory.h> using namespace std; const int MAX = 128; long long ans; int N, K, nCnt; b

HDOJ 2769 Disgruntled Judge 扩展GCD

扩展GCD: 枚举a,扩展GCD求b,再暴力检查 Disgruntled Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 329    Accepted Submission(s): 142 Problem Description Once upon a time, there was an nwerc judge with

HDU1073 Online Judge

Online Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5373    Accepted Submission(s): 2054 Problem Description Ignatius is building an Online Judge, now he has worked out all the problem

最小生成树-并查集-Kruskal-zoj-2048-special judge

Highways description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is aware of this problem and has already constructed a number of highways connecting som

Online Judge(字符串-格式)

Online Judge Problem Description Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user's result file, then the system compare the two files.

Online Judge for ACM-ICPC etc.

原文链接:http://blog.csdn.net/tigerisland45/article/details/52134189 Virtual Judge ACM-ICPC Live Archive - Home UVa Online Judge - Home Welcome To PKU JudgeOnline(POJ) Welcome to Hangzhou Dianzi University Online Judge(HDU) OpenJudge - 百练 - 首页(PKU) Codef

关于开源OJ_在线评测系统(Online Judge)设计与实现的研究与分析

OJ是Online Judge系统的简称,用来在线检测程序源代码的正确性.著名的OJ有TYVJ.RQNOJ.URAL等.国内著名的题库有北京大学题库.浙江大学题库.电子科技大学题库.杭州电子科技大学等.国外的题库包括乌拉尔大学.瓦拉杜利德大学题库等. Online Judge系统最初使用于ACM-ICPC国际大学生程序设计竞赛和OI信息学奥林匹克竞赛中的自动判题和排名.现广泛应用于世界各地高校学生程序设计的训练.参赛队员的训练和选拔.各种程序设计竞赛以及数据结构和算法的学习和作业的自动提交判断中