PTA who will fall first (15 points)

Article Directory

Topic restatement

7-5 Who pours first (15 points)
Punching 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 figure with their hands. If the number drawn by one person is exactly equal to the sum of the numbers shouted by the two, whoever loses, the loser will be fined a glass of wine. If two people win or lose together, the next round continues until the only winner appears.

The following is the amount of alcohol (the maximum number of drinks you can drink without pour) and the punching record of the two persons of A and B. Please judge which of the two drink first.

Input format:

Enter the first line to give the amount of alcohol for A and B (non-negative integer not exceeding 100), separated by spaces. The next line gives a positive integer N (≤100), followed by N lines, each line gives the record of a round of punching, the format is:
A shouts A strokes B shouts B strokes
where shout is the number shouted, and strokes are strokes. The numbers are all positive integers not exceeding 100 (draw with both hands).

Output format:

In the first line, output the person who fell first: A represents A, B represents B. The second line outputs how many cups the person who has not poured. The title guarantees that one person falls. Note that the program is terminated when someone falls down, and the subsequent data need not be processed.

Input sample:

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

code

#include <iostream>
using namespace std;
int main()
{
    
    
    int A,B,C,D,E,F,n,AN,BN;
    cin>>A>>B;
    cin>>n;
    AN=A;
    BN=B;
    for(int i=0;i<n;i++)
    {
    
    
        cin>>C>>D>>E>>F;
        if(D==(C+E)&&F!=(C+E)) {
    
    A--;}
        if(F==(C+E)&&D!=(C+E)) {
    
    B--;}
        if(A<0){
    
    cout<<'A'<<endl<<BN-B;break;}
        if(B<0){
    
    cout<<'B'<<endl<<AN-A;break;}
    }
}

Guess you like

Origin blog.csdn.net/weixin_44108271/article/details/109478958