参考代码:
#include<iostream> using namespace std; int main() { int n; cin >> n; string s1[n];//记录Player1的选择 string s2[n];//记录Player2的选择 for(int i = 0; i < n; i++) { cin >> s1[i] >> s2[i]; } for(int i = 0; i < n; i++) { if(s1[i][0] == s2[i][0])//先判断是否平局的情况 { cout << "Tie\n"; continue; }//接下来罗列出Player1获胜的所有情况,这一步通过判断首字符即可完成 if(s1[i][0] == 'R' && s2[i][0] == 'S' || s1[i][0] == 'S' && s2[i][0] == 'P' || s1[i][0] == 'P' && s2[i][0] == 'R') cout << "Player1\n"; else//剩余情况即为Player2获胜 cout << "Player2\n"; } return 0; }
0.0分
5 人评分