题解 | 纸牌游戏

纸牌游戏

https://www.nowcoder.com/practice/74f915e366094b19b94334de8b68e733

关键在于模拟游戏中比较的过程,理清获胜的条件是胜场大于负场,再从第一场和第二场的情况来判断是否获胜即可.

#include <iostream>
using namespace std;
bool judge(int a1,int a2,int b1,int b2){//将a1和b1比较,a2和b2比较
    if(a1>b1 && a2>=b2) return true; 
    if(a1==b1 && a2>b2) return true;   //胜场大于负场
    return false;//负场大于胜场
}
void solve(){
    int a1,a2,b1,b2;
    cin>>a1>>a2>>b1>>b2;
    int ans=0;
    if(judge(a1,a2,b1,b2)) ans++;
    if(judge(a1,a2,b2,b1)) ans++;
    if(judge(a2,a1,b1,b2)) ans++;
    if(judge(a2,a1,b2,b1)) ans++;
    cout<<ans<<endl;
}
int main() {
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

全部评论

相关推荐

牛客51274894...:照片认真的吗,找个专门拍证件照的几十块钱整端正点吧,要不就别加照片
点赞 评论 收藏
分享
今天 00:20
长沙学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务