POJ 2503 Babelfish (c + +) (Map container)

Source: Internet
Author: User

The main idea is to give two words, the previous word is the translation of the next word, that is, there is a key to the value of the mapping relationship, to enter the empty behavior sign end input correspondence, and then input the word output corresponding translation. So this problem can be solved by using the map container of C + + to establish correspondence relation.

The code is as follows:

1#include <iostream>2#include <map>3#include <cstdio>4#include <cstring>5 using namespacestd;6 intMain () {7     Charstr1[ *] ;8     Charkey[ *], value[ *] ;9map<string,string>Map_;Ten      while(Gets (str1)) { One         if(strcmp (STR1," /") ==0 ){ A              Break ; -         } -SSCANF (STR1,"%s%s", value, key);///reads from a string into data that matches the specified format the //Map_[key] = value; ///Two kinds of relationship of establishing key value can be; - Map_.insert (Make_pair (key, value)); -     } -      while(Gets (str1)) { +map<string,string>::iterator it;///iterators -it = Map_.find (STR1);///find out if this key is in MAP_ +         if(It! = Map_.end ()) {///If you find Acout << it->second << Endl;///Output Key value at}Else{ -cout <<"EH"<< Endl;///otherwise output eh -         } -     } -     return 0 ; -}

POJ 2503 Babelfish (c + +) (Map container)

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.