Hdoj/hdu 2537 8 Ball win (water problem. Simple judgment)

Source: Internet
Author: User

Problem Description
8 Ball is a game of billiards rules. The table has 7 red balls, 7 yellow ball and a black ball, and of course a white ball. For the subject, we use the following simplification rules: Red, yellow two players take turns with the white ball to hit their own color of the ball, if the color of the 7 balls in all, then the player can play black ball, if the hit in the count he wins. If you put the black ball in before hitting all the balls in your own color, you lose. If the player accidentally hits the opponent's ball, the ball will still be in effect.
Now give the order of the ball (except the white ball), and the black ball by which side, your task is to determine which side is the winner.
Suppose there is not a single shot in a black ball and other colored balls.

Input
The input contains multiple sets of data. The first row of each set of data is an integer N (1<=n<=15), which indicates the number of balls scored and the n=0 indicates the end. Then there is a row that contains n characters, which in turn indicates which ball is being scored. If it's ' B ', it means the black ball that red is hitting, and if it's ' L ', it's the black ball that Huangfang hit. If ' Y ' means yellow ball, ' R ' denotes red ball. There are no spaces between characters.
All inputs meet the following criteria: When the last ball hits the game is over, and the red and black balls are no more than 7.

Output
For each set of data, output one line. If the red side wins, output ' red '; Huangfang wins, output ' Yellow '.

Sample Input
5
Ryrrb
9
Rrrryrrrb
0

Sample Output
Yellow
Red

Simple question ~ First look at the last to hit the black Ball is who, and then see if he has yellow ball or red ball has been all hit in the ~ ~ ~

Import Java.util.Scanner; Public classMain { Public Static void Main(string[] args) {Scanner sc=NewScanner (System.inch); while(Sc.hasnext ()) {intn =sc.nextint ();if(n==0){ Break; } String str = Sc.next ();intR=0;inty=0; for(intI=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"); }            }        }    }}

Hdoj/hdu 2537 8 Ball win (water problem. Simple judgment)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.