1046 划拳,C

#include <stdio.h>

int main()
{
    int flag1,flag2,shout1,shout2,gesture1,gesture2,n,a=0,b=0;
    scanf("%d",&n);
    while(n--)
    {
        flag1=0;flag2=0;
        scanf("%d %d %d %d",&shout1,&gesture1,&shout2,&gesture2);
        if(gesture1 == (shout1+shout2))
            flag1++;
        if(gesture2 == (shout1+shout2))
            flag2++;
        if(flag1 && !flag2) b++;
        if(!flag1 && flag2) a++;
    }

    printf("%d %d",a,b);
    return 0;
}

下面是C++实现的,因为正在学习C++,顺便用这一题来试一下

#include <iostream>
using namespace std;

int main()
{
    int flag1,flag2,shout1,shout2,gesture1,gesture2,n,a=0,b=0;
    cin>>n;
    while(n--)
    {
        flag1=0;flag2=0;
        cin>>shout1;
        cin>>gesture1;
        cin>>shout2;
        cin>>gesture2;
        if(gesture1 == (shout1+shout2))
            flag1++;
        if(gesture2 == (shout1+shout2))
            flag2++;
        if(flag1 && !flag2) b++;
        if(!flag1 && flag2) a++;
    }

    cout<<a<<" "<<b;
    return 0;
}
发布了44 篇原创文章 · 获赞 0 · 访问量 861

猜你喜欢

转载自blog.csdn.net/weixin_43916400/article/details/104615974
今日推荐