题目描述
我的想法是可以把player1和player2 “出拳”的输赢关系做成一张表格来记录,即二维数组,Player1做行,Player2做列;Gun,Bear, Hunter三个字符串的长度分别为3,4,6,都减去3即是0,1,3,可以作为上面二维数组的第0,1,3行/列;Player1的赢,输, 平局分别对应二维数组中元素为1,0,-1。
C++ 代码
#include<iostream>
using namespace std;
int main()
{
string s1, s2;
int n;
cin >> n;
int a[4][4] = {0, 1, 0, -1, -1, 0, 0, 1, 0, 0, 0, 0, 1, -1, 0, 0};
while(n--)
{
cin >> s1 >> s2;
int i = s1.size() - 3, j = s2.size() - 3;
if(a[i][j] == 0) cout << "Tie" << endl;
else if(a[i][j] == 1) cout << "Player1" << endl;
else cout << "Player2" << endl;
}
return 0;
}