赞
踩
注意map的用法,一个键只能对应一个值,如果有一个键对应多个值,则会覆盖,或者用multimap
- #include<bits/stdc++.h>
- using namespace std;
- map<string,string>m;
- map<string,int>m1;
- int n,k;
- string s;
- int main()
- {
- scanf("%d %d",&n,&k);
- while(n--)
- {
- string s1,s2;
- cin>>s1>>s2;
- m[s1]=s2;
- }
- while(k--)
- {
- cin>>s;
- string ans1,ans2;
- if(m.count(s))
- {
- cout<<m[s]<<endl;
- continue;
- }
- for(auto i:m)
- {
- for(auto j:m)
- {
- string str1=i.first+j.first;
- string str2=i.first;
- if(str1==s)
- {
-
- ans1=i.second,ans2=j.second;
- m1[ans1+ans2]=1;
- }
- // else if(str2==s)
- // {
- //
- // ans1=i.second,ans2="";
- // m1[ans1+ans2]=1;
- // break;
- // }
- }
- }
- // cout<<flag<<endl;
- if(m1.size()==0||m1.size()>1)
- printf("D\n");
- else
- cout<<ans1+ans2<<endl;
- m1.clear();
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。