Nine degrees 1029-map-magic Spell Dictionary

Source: Internet
Author: User

The topic is to practice map because it is possible to find value from key, and value to find key two cases, so two map is required because map can only find value from key. It also tests the processing of strings.

#include <iostream> #include <map> #include <string> #include <cstdio>using namespace std;    int main () {map<string,string>maps;    map<string,string>maps1;    Map<string,string>::iterator F;    String A;    int n;        while (Getline (cin,a)) {if (a== "@[email protected]") break;        int end = A.find ('] ');        string tmp = A.SUBSTR (1,end-1);        String tmp1 = A.substr (End+2,a.length ()-1);        MAPS[TMP]=TMP1;    maps1[tmp1]=tmp;    } cin>>n;    GetChar ();        for (int i=0;i<n;i++) {getline (cin,a);            if (A.find (' [')!=-1) {a = A.substr (1,a.length ()-2);            f = Maps.find (a); if (F==maps.end ()) cout<< "What?"            <<endl;        else cout<<maps[a]<<endl;            } else{F = Maps1.find (a); if (F==maps1.end ()) cout<< "What?"            <<endl; else COUT&Lt;<maps1[a]<<endl; }} return 0;}


Nine degrees 1029-map-magic Spell Dictionary

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.