华为机试09.01 查找知识图谱中的实例知识(C++)

#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string str1, str2, str3;
    multimap<string, string> sub;
    multimap<string, string> ins;
    for (int i = 0; i < n; i++)
    {
        cin >> str1 >> str2 >> str3;
        if (str2 == "subClassOf")
            sub.insert(pair<string, string>(str3, str1));
        else if (str2 == "instanceOf")
            ins.insert(pair<string,string>(str3,str1));
    }
    string recv;
    cin >> recv;
    set<string> res;
    for (auto i : sub)
    {
        if (i.first == recv)
        {
            for (auto j : ins)
            {
                if (j.first == i.second)
                    res.insert(j.second);
            }
        }
    }
    for (auto i : ins)
    {
        if (i.first == recv)
            res.insert(i.second);
    }
    if (res.empty())
        cout << "empty" << endl;
    for (auto i : res)
    {
        cout << i << " ";
    }
    cout << endl;
}
全部评论
想问,这道题需要输出子类还有子类的这种情况吗?
点赞 回复 分享
发布于 2021-09-22 11:34
用multimap和map<string, vector<string>>哪个效率高呢
点赞 回复 分享
发布于 2021-09-08 21:22

相关推荐

05-21 15:47
门头沟学院 Java
浪漫主义的虹夏:项目有亮点吗,第一个不是纯玩具项目吗,项目亮点里类似ThreadLocal,Redis储存说难听点是花几十分钟绝大部分人都能学会,第二个轮子项目也没体现出设计和技术,想实习先沉淀,好高骛远的自嗨只会害了自己
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 10:56
点赞 评论 收藏
分享
评论
3
6
分享

创作者周榜

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