#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
// 谁能吃谁的映射
unordered_map<string, string> eat = {
{"elephant", "tiger"},
{"tiger", "cat"},
{"cat", "mouse"},
{"mouse", "elephant"}
};
if (eat[s1] == s2) {
cout << "win" << endl;
} else if (eat[s2] == s1) {
cout << "lose" << endl;
} else {
cout << "tie" << endl;
}
return 0;
}
谁吃谁,字符串映射:
它是比 map 更快的一种字典容器(底层用哈希表实现)。
💡 注意:
使用 unordered_map 需要 #include <unordered_map>。

京公网安备 11010502036488号