题解 | #代理服务器#
代理服务器
https://www.nowcoder.com/practice/1284469ee94a4762848816a42281a9e0
#include <iostream> #include <map> using namespace std; int main(){ int n,m,count=0; while (cin>>n){ map<string,bool> dnsMap; string str; for (int i = 0; i < n; ++i) { cin>>str; dnsMap[str] = true; } cin>>m; for (int i = 0; i < m; ++i) { cin>>str; if (dnsMap.find(str) != dnsMap.end()){ dnsMap[str] = false; } int flag = false; map<string,bool>::iterator it; for (it=dnsMap.begin();it!=dnsMap.end();it++) { if (it->second) flag = true; } if (!flag){ count++; for (it=dnsMap.begin();it!=dnsMap.end();it++) { it->second = true; } dnsMap[str] = false; } } if (count==m) count = -1; cout<<count<<endl; } return 0; }