当前位置:网站首页>L1-019 who goes first (15 points)

L1-019 who goes first (15 points)

2022-06-24 07:49:00 Code Knight

Boxing is an interesting part of the ancient Chinese wine culture . The method of two people on the wine table is : Shout out a number from each mouth , Draw a number with your hand . If someone's number is exactly equal to the sum of the two Numbers , Who is lost , The loser gets a glass of wine . Either a win or a loss goes on to the next round , Until the only winner comes along .

So let's give you a 、 B how much for two ( How many cups can you drink at most ) And punching records , Please judge which of the two should go first .

Input format :

The first line of input gives us a 、 B how much for two ( No more than 100 Non-negative integer ), Space off . The next line gives a positive integer N(≤100), And then N That's ok , Each line gives a record of one stroke , The format is :

 A shout   A stroke   Ethyl shout   B row 

among shout It's the number called out , draw It's a number , No more than 100 The positive integer ( Row with both hands ).

Output format :

Output the first person to fall on the first line :A On behalf of a ,B On behalf of the b . The second line shows how many drinks the person who didn't pour had . They guarantee that one person will fall . Note that the program terminates when someone drops , You don't have to deal with the rest of the data .

sample input :

1 1
6
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
15 1 1 16

sample output :

A
1

Ideas :

        ① data structure : Structure

        ② Algorithm : Compare

Source code :

#include<iostream>
using namespace std;

struct A
{
	int max;
	int han;
	int hua;
	int d;
}a;

struct B
{
	int max;
	int han;
	int hua;
	int d;
}b;

int ans_r;
char ans_c;
int key=0;//key=0, There is no answer  

int main()
{
	cin>>a.max>>b.max;
	
	int round;

	cin>>round;
	
	a.d=0;b.d=0;
	
	for(int i=0;i<round;i++)
	{
		cin>>a.han>>a.hua>>b.han>>b.hua;
		if(a.hua==b.han+a.han)
		{
			a.d++;	
			b.hua==b.han+a.han;
			if(a.hua==b.hua)
				a.d--;
		}
		if(b.hua==b.han+a.han)
		{
			b.d++;	
			a.hua==b.han+a.han;
			if(a.hua==b.hua)
				b.d--;
		}
		if(a.d>a.max&&key==0)
		{
			ans_c='A';
			ans_r=b.d; 
			key=1;
		}
		if(b.d>b.max&&key==0)
		{
			ans_c='B';
			ans_r=a.d;
			key=1; 
		}	
	} 
	if(key==1)
	{
		cout<<ans_c<<endl<<ans_r;
	}
	return 0;
} 

原网站

版权声明
本文为[Code Knight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240351283835.html