PAT-B 1046 Punch (15 points)

1046 Boxing (15 points)
Boxing is an interesting part of ancient Chinese wine culture. The method for two people at the wine table is to call out a number from each person, and at the same time make a number with their hands. If the number drawn by one person is exactly equal to the sum of the numbers shouted by the two, whoever wins, the loser will be fined a glass of wine. If two people win or lose together, the next round will continue until the only winner appears.

Below are the punching records of A and B. Please count how many glasses they drank in the end.

Input format:

Enter the first line and give a positive integer N (≤100), and then N lines, each line gives the record of a round of punches, the format is:
A call a stroke B call B stroke

Output format:

Output the number of drinking glasses of A and B in one line, separated by a space.

Input sample:

5
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
Output example:

1 2

Idea:
Use continue to simulate a win-win or lose-lose situation.

#include<iostream> 
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm> 
using namespace std;
int main()
{
    
    

int N,jia_han,jia_hua;
int yi_han,yi_hua;
int jh=0,yh=0;  //甲喝和乙喝的杯数。 
cin>>N;
	for(int i=0;i<N;i++)
	{
    
    
		cin>>jia_han>>jia_hua;  //甲喊,甲划 
		cin>>yi_han>>yi_hua;  //乙喊,乙划 
		int sum=jia_han+yi_han; 
	
	     if(jia_hua==sum &&  yi_hua!=sum )   yh++; 
	else if(yi_hua==sum &&  jia_hua!=sum)    jh++; 
	else if(yi_hua==sum &&  jia_hua==sum) continue;
    else if(yi_hua!=sum &&  jia_hua!=sum) continue;
	}
	cout<<jh<<" "<<yh<<endl; 
 } 

Insert picture description here

Guess you like

Origin blog.csdn.net/SKMIT/article/details/113816830