54 条题解
-
-3
且看我暴走if#include <iostream> using namespace std; int main() { int t, k; cin >> t >> k; if (t == 1) { if (k == 1) { cout << "tie"; } else if (k == 2) { cout << "win"; } else { cout << "lose"; } } else if (t == 2) { if (k == 1) { cout << "lose"; } else if (k == 2) { cout << "tie"; } else { cout << "win"; } } else { if (k == 1) { cout << "win"; } else if (k == 2) { cout << "lose"; } else { cout << "tie"; } } return 0; }
-
-3
不会就我写的很长吧👀️ 题解来喽
#include<iostream> using namespace std; int main() { int T , K; cin >> T >> K; for (int i = 1;i <= 1;i++)//这里我用了一次循环哈(我闲的👀️ ) { if (T == K) { cout << "tie"; break;//跳出循环,不需要再判断了 } if (T == 1)//下面都是判断了 { if(K == 2) { cout << "win"; } else { cout << "lose"; } } else if (T == 2) { if (K == 1) { cout << "lose"; } else{ cout << "win"; } } else { if(K == 1) { cout << "win"; } else { cout << "lose"; } } } return 0; }
-
-3
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; if(a == 1 && b == 2) { cout<<"win"; } else if(a == 1 && b == 3) { cout<<"lose"; } else if(a == 2 && b == 1) { cout<<"lose"; } else if(a == 2 && b == 3) { cout<<"win"; } else if(a == 3 && b == 1) { cout<<"win"; } else if(a == 3 && b == 2) { cout<<"lose"; } else { cout<<"tie"; } return 0; }🚀️ 小盆友放心食用, 已AC.
-
-3
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; if(a == 1 && b == 2) { cout<<"win"; } else if(a == 1 && b == 3) { cout<<"lose"; } else if(a == 2 && b == 1) { cout<<"lose"; } else if(a == 2 && b == 3) { cout<<"win"; } else if(a == 3 && b == 1) { cout<<"win"; } else if(a == 3 && b == 2) { cout<<"lose"; } else { cout<<"tie"; } return 0; }
-
-3
可以用int类型的计算来判断结果,这样就变成了5种结果,再用表示或的“||”符只需用几个if了(
#include <bits/stdc++.h> using namespace std; int main() { int a,b;cin>>a>>b; if((b-a==1)||(b-a==-2))//当差为正1(1,2和2,3的结果)和负2时(1,3的结果)就赢 { cout<<"win"; } else if((b-a==2)||(b-a==-1))//当差为正2(3,1的结果)和负1时(2,1和3,2的结果)就输 { cout<<"lose"; } else { cout<<"tie"; } return 0; }
算式为b-a,不用负数也可以把算式搞成a-b,
你也可以用绝对值(被打) -
-3
这道题只要分类枚举,判断所有情况即可。核心代码:
#include <iostream> using namespace std; int main() { int a,b; cin >> a >> b; if (a == b) { cout << "tie"; } else if (a == 1) { if (b == 2) { cout << "win"; } else if (b == 3) { cout << "lose"; } } else if (a == 2) { if (b == 3) { cout << "win"; } else if (b == 1) { cout << "lose"; } } else if (a == 3) { if (b == 1) { cout << "win"; } else if (b == 2) { cout << "lose"; } } return 0; }
-
-3
题目看着很长,实际就是a,b=(1,2,3)。每个人都有3种情况,一共9种出拳组合,利用if-else if-else 写清楚这个关系即可。
if (a == b) { cout << "tie"; } else if (a == 1) { if (b == 2) { cout << "win"; } else if (b == 3) { cout << "lose"; } } else if (a == 2) { if (b == 3) { cout << "win"; } else if (b == 1) { cout << "lose"; } } else if (a == 3) { if (b == 1) { cout << "win"; } else if (b == 2) { cout << "lose"; } }
信息
- ID
- 43
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 3
- 标签
- 递交数
- 3937
- 已通过
- 2031
- 上传者