string型二叉树
既然是二叉树的话,就手动还原一下好了;
然后能发现每两个节点中的第三个字母都是不一样,那么手动提取出来就能简化coding输入啦;
找分支的时候就对比第三个字母。
Cpp代码
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "__rvemseriibmrmi";
auto tree = str.c_str();
string res[8] = {"aguia", "pomba", "homem", "vaca", "pulga", "lagarta", "sanguessuga", "minhoca"};
int index = 2;
string _in;
while (index < 16){
cin >> _in;
if (_in[2] == tree[index]) index *=2;
else index = (index + 1) * 2;
}
index = index / 2 - 8;
cout << res[index];
return 0;
}