Noi question Bank (noi.openjudge.cn) 3.9 data structure C++stl T1--T2

Source: Internet
Author: User
Tags unique id

T1 1806: Dictionary

Describe

You have traveled to a foreign city. The people there speak foreign languages you can't understand. Fortunately, you have a dictionary to help you.

Enter first a dictionary that contains no more than 100,000 entries, each of which occupies one line. Each entry includes an English word and a foreign language word, separated by a space between two words. And there will be no more than two occurrences of a foreign word in the dictionary. The dictionary is followed by a blank line, and a document consisting of a foreign word is given, with no more than 100000 lines, and each line includes only one foreign word. The words that appear in the input include only lowercase letters and do not exceed 10 in length. Output in the output, you need to translate the input documents into English, each line output an English word. If a foreign word is not in the dictionary, translate the word into "eh".

Sample input

Dog Ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Sample output

Catehloops
Read-in note, do not read a single character, it is difficult to set the read-in end condition, read in the behavior unit, the beginning of the empty character for the read-in end condition

SSCANF (c, "%s%s", A, b); Divides the string C with a space into two strings, a, A, a, b
#include <iostream>#include<map>#include<cstdio>using namespaceStd;map<string,string>MP;Chara[ One],b[ One],c[ A];intMain () { while(Gets (c) &&c[0]) {sscanf (c,"%s%s", A, b); MP[B]=A; }     while(Gets (c) &&c[0])    {        if(Mp.find (c)!=mp.end ()) cout<<mp[c]<<Endl; Elsecout<<"EH"<<Endl; }} 
View Code

T2 3339:list
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
Can be used to practice list
#include <iostream>#include<list>#include<cstring>#include<iterator>using namespacestd;intN,id1,id2;strings;list<int>lit[10001];intMain () {CIN>>N;  for(intI=1; i<=n;i++) {cin>>s; if(s=="New") cin>>id1; Else if(s=="Add") {cin>>id1>>Id2; Lit[id1].push_back (ID2);//List[id1] Insert element after Id2        }        Else if(s=="Merge") {cin>>id1>>Id2; Lit[id1].merge (Lit[id2]);//List[id2] list[id1], and empty List[id2]        }        Else if(s=="Unique") {cin>>id1; Lit[id1].sort ();//SortLit[id1].unique ();//go to the heavy, unique can only go to re-order the adjacent elements, so the first        }        Else//Output{cin>>id1; if(!lit[id1].empty ())//first Judge non-empty{lit[id1].sort ();//Sortostream_iterator<int> Output (cout," "); Copy (Lit[id1].begin (), lit[id1].end (), output);//output, separated by a spacecout<<Endl; }            Elsecout<<Endl; }    }}
View Code



Noi question Bank (noi.openjudge.cn) 3.9 data structure C++stl T1--T2

Related Article

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.