用string的size之差表示player1赢的三种情况
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
string x, y;
while (n --)
{
cin >> x >> y;
int a = x.size(), b = y.size();
if (a - b == -1 || a - b == -2 || a - b == 3)
cout << "Player1" << endl;
else if (a == b)
cout << "Tie" << endl;
else cout << "Player2" << endl;
}
return 0;
}
想法很妙但是有点取巧,可能还是用012分别表示变量,构造函数关系判断通用一点
while(1) printf(“666”);
牛哇!一行一个死循环(doge)
个人觉得如果看字符串长度判断的话,只能针对这个题。有没有一种通解办法,也可以适用类似猜拳的所有题目
#include[HTML_REMOVED]
#include[HTML_REMOVED]
using namespace std;
int main(void) {
int t; cin >> t; string s1; string s2;
for (int i = 0; i < t; i++)
{
cin >> s1; cin >> s2;
if (s1 == s2)cout << “Tie”;
else if (s1 == “Gun” && s2 == “Bear” || s1 == “Bear” && s2 == “Hunter” || s1 == “Hunter” && s2 == “Gun”)cout << “Player1”;
else cout << “Player2”;
if (i < t - 1)cout << endl;
}
}
?
Orz
#include[HTML_REMOVED]
using namespace std;
int main() {
string a,b;
int n;
cin>>n;
while(n–){
cin>>a>>b;
if(a==”Hunter”){
if(b==”Gun”) cout<<”Player1”<<endl;
else if(b==”Bear”) cout<<”Player2”<<endl;
else cout<<”Tie”<<endl;
}
else if(a==”Gun”){
if(b==”Bear”) cout<<”Player1”<<endl;
else if(b==”Hunter”) cout<<”Player2”<<endl;
else cout<<”Tie”<<endl;
}
else if(a==”Bear”){
if(b==”Hunter”) cout<<”Player1”<<endl;
else if(b==”Gun”) cout<<”Player2”<<endl;
else cout<<”Tie”<<endl;
}
}
return 0;
}
orz
orz
Orz
666
nb
nbnbnbnbnbnbnnbnbnbnbnbnbnb
#666
🐂
sto
Orz
女少
nb、
cout << “优雅,太优雅了“ <<endl;