题目描述:
8球是一种台球竞赛的规则。台面上有7个红球、7个黄球以及一个黑球,当然还有一个白球。对于本题,我们使用如下的简化规则:红、黄两名选手轮流用白球击打各自颜色的球,如果将该颜色的7个球全部打进,则这名选手可以打黑球,如果打进则算他胜。如果在打进自己颜色的所有球之前就把黑球打进,则算输。如果选手不慎打进了对手的球,入球依然有效。
现在给出打进的球(白球除外)的顺序,以及黑球由哪方打进,你的任务是判定哪方是胜者。
假设不会有一杆同时打进一颗黑球和其他彩球。
现在给出打进的球(白球除外)的顺序,以及黑球由哪方打进,你的任务是判定哪方是胜者。
假设不会有一杆同时打进一颗黑球和其他彩球。
水题,直接AC代码:
using System;
namespace a1
{
class Program
{
public static int search(string s,int n){
int a,t=0;
char[] ch=s.ToCharArray();
if(n==1){
a=s.IndexOf("B");
for(int i=0;i<a;i++)
if(ch[i]=='R') t++;
}
else{
a=s.IndexOf("L");
for(int i=0;i<a;i++)
if(ch[i]=='Y') t++;
}
return t;
}
public static void Main(string[] args)
{
int n;
string str = string.Empty;
while ((str = Console.ReadLine()) != null) {
n = Convert.ToInt32(str);
if(n==0) break;
str=Console.ReadLine();
if(str.IndexOf("B")>=0){
if(search(str,1)==7) Console.WriteLine("Red");
else Console.WriteLine("Yellow");
}
else{
if(search(str,0)==7) Console.WriteLine("Yellow");
else Console.WriteLine("Red");
}
}
}
}
}