PAT_划拳

来源:互联网 发布:mac提醒没有推出u盘 编辑:程序博客网 时间:2024/05/01 13:55
/** * 划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。 * 如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮, * 直到唯一的赢家出现。下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。输入格式:输入第一行先给出一个正整数N(<=100),随后N行,每行给出一轮划拳的记录,格式为:甲喊 甲划 乙喊 乙划其中“喊”是喊出的数字,“划”是划出的数字,均为不超过100的正整数(两只手一起划)。输出格式: 在一行中先后输出甲、乙两人喝酒的杯数,其间以一个空格分隔。 */import java.util.Scanner;public class Main {private static Scanner sc;private static int jia = 0,yi = 0;public static void main(String[] args) {sc = new Scanner(System.in);int n = sc.nextInt();for (int i = 0; i < n; i++) {int x1 = sc.nextInt();int x2 = sc.nextInt();int y1 = sc.nextInt();int y2 = sc.nextInt();int z = x1+y1;if(x2 == z && y2 != z){jia++;}else if(y2 == z & x2 != z){yi++;}}System.out.println(yi+" "+jia);/*Huaquan[] hq = new Huaquan[n];for (int i = 0; i < n; i++) {hq[i] = new Huaquan(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());}for (int i = 0; i < n; i++) {int x = hq[i].getJhua();int y = hq[i].getYhua();int z = hq[i].getJhan() + hq[i].getYhan();if(x == z && y != z){jia++;}else if(y == z & x != z){yi++;}}System.out.println(yi+" "+jia);*/}static class Huaquan{private int jhan;private int jhua;private int yhan;private int yhua;public int getJhan() {return jhan;}public int getJhua() {return jhua;}public int getYhan() {return yhan;}public int getYhua() {return yhua;}public Huaquan(int jhan, int jhua, int yhan, int yhua) {super();this.jhan = jhan;this.jhua = jhua;this.yhan = yhan;this.yhua = yhua;}}}

0 0
原创粉丝点击