zoukankan      html  css  js  c++  java
  • PAT——1046. 划拳

    划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。

    下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。

    输入格式:

    输入第一行先给出一个正整数N(<=100),随后N行,每行给出一轮划拳的记录,格式为:

    甲喊 甲划 乙喊 乙划

    其中“喊”是喊出的数字,“划”是划出的数字,均为不超过100的正整数(两只手一起划)。

    输出格式:

    在一行中先后输出甲、乙两人喝酒的杯数,其间以一个空格分隔。

    输入样例:

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

    输出样例:

    1 2


     1 package com.hone.basical;
     2 
     3 import java.util.Scanner;
     4 /**
     5  * 原题目:https://www.patest.cn/contests/pat-b-practise/106
     6  * @author Xia
     7  * 就是用一个if判断,重点是:别将所有的元素存储起来,而是一边输入一边判断。
     8  */
     9 public class basicalLevel1046guessFist {
    10 
    11     public static void main(String[] args) {
    12         int j = 0;
    13         int y = 0;
    14         Scanner in = new Scanner(System.in);
    15         int n = Integer.parseInt(in.nextLine());
    16         for (int i = 0; i < n; i++) {
    17             int jhan = in.nextInt();
    18             int jhua = in.nextInt();
    19             int yhan = in.nextInt();
    20             int yhua = in.nextInt();
    21             int total = jhan+yhan;
    22             if (jhua==total&&yhua!=total) {
    23                 y++;
    24             }
    25             if (yhua==total&&jhua!=total) {
    26                 j++;
    27             }
    28         }
    29         System.out.print(j+" ");
    30         System.out.print(y);
    31     }
    32 }
  • 相关阅读:
    break (Statements) – JavaScript 中文开发手册
    :first-of-type (Selectors) – CSS 中文开发手册
    no-new-symbol (Rules) – Eslint 中文开发手册
    Null-terminated byte strings (Strings) – C 中文开发手册
    HTML DOM Time 对象
    Java 实例 – 向文件中追加数据
    HTML DOM Hidden type 属性
    在Java中扩展原始转换
    字体变位 | font-variant-position (Fonts) – CSS 中文开发手册
    逆波兰计算器完整版
  • 原文地址:https://www.cnblogs.com/xiaxj/p/7997519.html
Copyright © 2011-2022 走看看