PTA刷题Basic篇——1046.划拳——Day(23)

问题描述

在这里插入图片描述

题目分析

这道题目非常简单了,声明两个变量表示二者的喝酒数目。边输入边计算,二者划出的数字是否等于喊出数字之和。如果二者划出数字相等直接跳过 ,因为此时无论是不是喊出数字加和,都不喝酒。

代码

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;//划拳次数
    scanf("%d",&n);
    int lose1 = 0;
    int lose2 = 0;
    for(int i = 0;i < n;i++)
    {
        int h1,c1,h2,c2;
        scanf("%d %d %d %d",&h1,&c1,&h2,&c2);
        if(c1 == h1 + h2 && c2 != c1)
            lose2++;
        else if(c2 == h1 + h2 && c1 != c2)
            lose1++;
        else if(c1 == c2)
            continue;
    }
    printf("%d %d",lose1,lose2);
    return 0;
}

答题用时6min
Q46——finish√

原创文章 101 获赞 13 访问量 2321

猜你喜欢

转载自blog.csdn.net/weixin_44755413/article/details/105852771