Open Judge 3339 List

Source: Internet
Author: User
Tags strcmp

3339:list
Total time limit:
4000ms
Memory Limit:
65536kB
Describe

Write a program to complete the following commands:
New id--Create a sequence with a specified ID (id<10000)
Add ID num--adds integer num to a sequence numbered ID
Merge Id1 id2--merges the number in the sequence ID1 and Id2 and empties the ID2
Unique id--removes duplicate elements from the sequence ID
Out id--elements in a sequence with a small to large output number ID, separated by a space

Input
The first row is a number n, which indicates how many commands (n<=200000). One command per line after n rows.
Output
output According to the requirements of the topic.
Sample input
16new 1new 2add 1 1add 1 2add 1 3add 2 1add 2 2add 2 3add 2 4out 1out 2merge 1 2out 1out 2unique 1out 1
Sample output
1 2 3 1 2 3 41 1 2 2 3 3 41 2 3 4
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <list>5#include <map>6 using namespacestd;7 8map<int,list<int> >m;9 Ten intn,x,y; One Charop[10000]; A intMain () { -scanf"%d",&n); -      while(n--){ thescanf"%s", op); -         if(strcmp (OP,"New")==0){ -scanf"%d",&x); -M.insert (map<int,list<int> >::value_type (x,list<int>())); +         } -         if(strcmp (OP,"Add")==0){ +scanf"%d%d",&x,&y); A m[x].push_back (y); at         } -         if(strcmp (OP,"Merge")==0){ -scanf"%d%d",&x,&y); - M[x].merge (M[y]); -             //m[y].clear (); -         } in         if(strcmp (OP,"Unique")==0){ -scanf"%d",&x); to M[x].sort (); + M[x].unique (); -         } the         if(strcmp (OP," out")==0){ *scanf"%d",&x); $ M[x].sort ();Panax Notoginsenglist<int>:: iterator it; -              for(It=m[x].begin (); It!=m[x].end (); it++){ theprintf"%d",*it); +             } Aprintf"\ n"); the         } +     } -}

Since there is a list of the STL, the long experience is really ~ ~ ~

Open Judge 3339 List

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.