1046 Finger Guessing Game, 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;
}

Below is implemented in C ++, because C ++ is learning, the way to try to use this title

#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;
}
Published 44 original articles · won praise 0 · Views 861

Guess you like

Origin blog.csdn.net/weixin_43916400/article/details/104615974