文章
5
粉丝
153
获赞
1
访问
5.8k
#include <iostream>
#include <map>
#include <string>
using namespace std;
struct Parents {
char p1;
char p2;
};
map<char, Parents> tree;
string findRelation(char child, char parent, string relation = "") {
if (tree.count(child) == 0) {
return "-";
}
Parents parents = tree[child];
if (parents.p1 == parent || parents.p2 == parent) {
return relation.empty() ? "parent" : relation;
}
string relation1 = findRelation(parents.p1, parent, relation.empty() ? "grandparent" : "great-" + relation);
if (relation1 != "-") {
return relation1;
}
string relation2 = findRelation(parents.p2, parent, relation.empty() ? "grandparent" : "great-" + relation);
if (relation2 != "-") {
return relation2;
}
return "-";
}
string findChildRelation(char parent, char child, string relati...
登录后发布评论
暂无评论,来抢沙发