L1-019 谁先倒 (15分)
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805118568873984
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int lim_A = sc.nextInt(); // A的极限
int lim_B = sc.nextInt(); // B的极限
int count_A = 0; // 计数器,记录A喝了几杯
int count_B = 0; // 计数器,记录B喝了几杯
int t = sc.nextInt();
for(int i=0; i<t; i++){
int say_A = sc.nextInt(); // A喊
int hand_A = sc.nextInt(); // A划
int say_B = sc.nextInt(); // B喊
int hand_B = sc.nextInt(); // B划
int num = say_A + say_B;
// 下面是三种情况的判断:
// A和B同时赢或同时输,跳过一次循环
if(hand_A == hand_B){
continue;
}
// A输了,喝酒,计数器加一
if(hand_A == num){
count_A++;
if(count_A > lim_A){ // 当A喝的酒超过极限,输出并退出循环
System.out.println("A");
System.out.println(count_B);
break;
}
}
// B输了,喝酒,计数器加一
if(hand_B == num){
count_B++;
if(count_B > lim_B){// 当B喝的酒超过极限,输出并退出循环
System.out.println("B");
System.out.println(count_A);
break;
}
}
}
}
}