题解 | #代理服务器#

代理服务器

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;
}

全部评论

相关推荐

点赞 评论 收藏
分享
05-01 22:41
中南大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务