版本比较
题解:P13986 [PO Final 2023] 降重 / Synonyms
正文
增加 4 行删除 4 行
15 行未改动161718192020212223242526252627282930313233343535363738394015 行未改动#define ll long longconst int N=1e6+5;ll n,m;string a,b;map<string,string> mp,to;//mp判重,to记同义词 map<string,string> mp,to;//mp判重,to记同义词int main(){ cin>>n; for(ll i=1;i<=n;i++){ cin>>a>>b; if(mp.count(b)>0){//判重,count检查map中是否存在具有特定键的元素,存在返回1 to[mp[b]]=a;//同义词对(mp[b],a)和(a,mp[b])都要存 if(mp.count(b)>0){//判重,count检查map中是否存在具有特定键的元素,存在返回1 to[mp[b]]=a;//同义词对(mp[b],a)和(a,mp[b])都要存 to[a]=mp[b]; }else{ mp[b]=a; } } cin>>m; for(ll i=1;i<=m;i++){ cin>>a; if(to.count(a)==0) to[a]=a;//没有同义词就不变 if(to.count(a)==0) to[a]=a;//没有同义词就不变 cout<<to[a]<<" "; } return 0;}```