懒省事的小名

xiaoxiao2021-02-28  89

懒省事的小名

时间限制: 1 Sec   内存限制: 12 MB 提交: 137   解决: 55 [ 提交][ 状态][ 讨论版]

题目描述

小名总结了一个英语近义词的词典(很厚哦,有多厚,你猜),词典实在太厚了,你需要帮助他写一个程序,输入一个单词,输出它的近义词

输入

第一行输入近义词的个数N和小名要查询的行数M

接下来N行为近义词对

M行单词,根据单词,输出它的近义词

输出

输出近义词,每个近义词占一行

样例输入

2 2 abc cba aaa bbb abc aaa

样例输出

cba

bbb

#include<iostream> #include<string.h> #include<map> using namespace std; int main() { int N,M,i; map<string,string>mapstring1; string str1,str2,str; cin>>N>>M; for(i=0;i<N;i++) { cin>>str1; cin>>str2; mapstring1[str1]=str2; } while(M--) { cin>>str; map<string,string>::iterator it; for(it=mapstring1.begin();it!=mapstring1.end();it++) { if((*it).first==str) cout<<(*it).second<<endl; if((*it).second==str) cout<<(*it).first<<endl; } } return 0; }

转载请注明原文地址: https://www.6miu.com/read-64551.html

最新回复(0)