HDOJ/HDU 2537 8球胜负(水题.简单的判断)

Problem Description
8球是一种台球竞赛的规则。台面上有7个红球、7个黄球以及一个黑球,当然还有一个白球。对于本题,我们使用如下的简化规则:红、黄两名选手轮流用白球击打各自颜色的球,如果将该颜色的7个球全部打进,则这名选手可以打黑球,如果打进则算他胜。如果在打进自己颜色的所有球之前就把黑球打进,则算输。如果选手不慎打进了对手的球,入球依然有效。
现在给出打进的球(白球除外)的顺序,以及黑球由哪方打进,你的任务是判定哪方是胜者。
假设不会有一杆同时打进一颗黑球和其他彩球。

Input
输入包含多组数据。每组数据第一行是一个整数N(1<=N<=15),表示打进的球的个数,N=0表示结束。随后有一行,包含N个字符,依序表示打进的是何种球。如果是’B’,表示是红方打进的黑球,如果是’L’,表示是黄方打进的黑球。如果是’Y’则表示是黄球,’R’表示红球。字符间没有空格。
所有输入都满足如下条件:最后一颗球打进时这局比赛正好结束,而且打进的红球和黑球都不超过7个。

Output
对每组数据,输出一行。如果红方胜,输出’Red’;黄方胜,输出’Yellow’。

Sample Input
5
RYRRB
9
RRRRYRRRB
0

Sample Output
Yellow
Red

简单题~先看最后打进那个黑球的是谁,再看他是不是把黄球或者红球已经全部打进去了~~~

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc= new Scanner(System.in);
        while(sc.hasNext()){
            int n =sc.nextInt();
            if(n==0){
                break;
            }
            String str = sc.next();
            int r=0;
            int y=0;
            for(int i=0;i<str.length()-1;i++){
                if(str.charAt(i)=='R'){
                    r++;
                }
                if(str.charAt(i)=='Y'){
                    y++;
                }
            }
            if(str.charAt(str.length()-1)=='B'){
                if(r==7){
                    System.out.println("Red");
                }else{
                    System.out.println("Yellow");
                }
            }else{
                if(y==7){
                    System.out.println("Yellow");
                }else{
                    System.out.println("Red");
                }
            }
        }
    }
}
时间: 2024-08-02 05:46:27

HDOJ/HDU 2537 8球胜负(水题.简单的判断)的相关文章

HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)

Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only tw

HDOJ(HDU) 1555 How many days?(水题)

Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, k,(2 <= k <= M <= 1000).M = 0, k = 0代表输入结束. Output 对于每个测试实例输出一个整数,表示M元可以用的天数. Sample Input 2 2 4 3 0 0 Sample Output 3 5 水题.... import java.util.

HDOJ(HDU) 1562 Guess the number(水题,枚举就行)

Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let (1) x % a = 0; (2) (x+1) % b = 0; (3) (x+2) % c = 0; and a, b, c are integers between 1 and 100. Given a,b,c, tell me what is the

hdu 2357 8球胜负

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2537 提示:就找是'B'和'L'的时候,看看是谁赢就行了 Problem Description 8球是一种台球竞赛的规则.台面上有7个红球.7个黄球以及一个黑球,当然还有一个白球.对于本题,我们使用如下的简化规则:红.黄两名选手轮流用白球击打各自颜色的球,如果将该颜色的7个球全部打进,则这名选手可以打黑球,如果打进则算他胜.如果在打进自己颜色的所有球之前就把黑球打进,则算输.如果选手不慎打进了对手

HDOJ(HDU) 2137 circumgyrate the string(此题用Java-AC不过!坑)

此题如果有用JavaACDSee,请评论,谢谢了. Problem Description Give you a string, just circumgyrate. The number N means you just circumgyrate the string N times, and each time you circumgyrate the string for 45 degree anticlockwise. Input In each case there is string

HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)

此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer among them, you hav

HDOJ/HDU 1256 画8(绞下思维~水题)

Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一个整数,字符表示画笔,整数(>=5)表示高度. Output 画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形. 每画一个"8"应空一行,但最前和最后都无空

HDOJ(HDU) 1859 最小长方形(水题、、)

Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内. Input 测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于 231:一对0 坐标标志着一个测试用例的结束.注意(0, 0)不作为任何一个测试用例里面的点.一个没有点的测试用例标志着整个输入的结束. Output 对每个测试用例,在1行内输出2对整数

HDOJ/HDU 2560 Buildings(嗯~水题)

Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N