zoukankan      html  css  js  c++  java
  • 实验7:Problem F: STL——字典

    Description

    输入n个字符串对(str1,str2),再输入k个查询字符串str,从字符串对中查找查询字符串,即如果str=str2,则输出str1,如果查询不到则输出"eh"(不包含引号)。输入保证所有字符串对的str2不相同,字符串只含有字母和数字,长度小于20!

    Input

    输入包含多组数据,直到文件结尾。

    每组数据第一行包含一个整数n(0≤n≤10^5)。接下来n行,每行描述一个字符串对。

    接下来包含一个整数m(0≤m≤10^5)。接下来m行,每行描述一个查询字符串。

    见样例

    Output

    输出每个查询的结果。

    Sample Input

    5 dog ogday cat atcay pig igpay froot ootfray loops oopslay 3 atcay ittenkay oopslay

    Sample Output

    cat eh loops

    HINT

    用STL的map容易实现


    Append Code

    #include<map>
    #include<string>
    #include<iostream>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        int i,n;
        ///char *w,*p;
        string w,p;
        map<string,string> d;
        while(cin>>n)
        {
            d.clear();
            while(n--)
        {
            /*scanf("%s",&w);
            w[sizeof(w)]='';
            scanf("%s",&p);
            p[sizeof(p)]='';*/
    
            cin>>w;
            cin>>p;
            d[p]=w;
        }
    
        cin>>n;
        ///scanf("%d",&m);
        while(n--)
        {
            ///char *tmp;
            string tmp;
            ///scanf("%s",&tmp);
            ///tmp[sizeof(tmp)]='';
            cin>>tmp;
            if(d.count(tmp)!=0)
                cout<<d[tmp]<<endl;
            else cout<<"eh"<<endl;
        }
        }
    
        return 0;
    }
    向代码最深处出发~!
  • 相关阅读:
    How do I change a .txt file to a .c file?
    [CQOI2007]余数求和
    CSP-J总结&题解
    【CSP游记S】
    [LuoguP1462]通往奥格瑞玛的道路
    归并排序——逆序对
    [NOIP 2011]选择客栈
    [二分图初步]【模板】二分图匹配,匈牙利算法
    [NOIP 2018]旅行
    黑魔法师之门 (magician)-并查集
  • 原文地址:https://www.cnblogs.com/auto1945837845/p/5408911.html
Copyright © 2011-2022 走看看