HDU 2537 8球胜负(模拟)

 1 /*这是一个模拟题,模拟一种台球的进球过程,并且判定胜负。
 2 对于输入的字符串,如果出现R则红方记1分,如果出现Y则黄方记1分。
 3 最后根据哪一方打进黑球和得分情况判定胜负。
 4 程序说明:
 5 这里给出两个C语言程序,一个没有使用数组(正解),另外一个是使用了数组来存储字符串。
 6 函数scanf()不会读走数后面的'
',所有需要用函数getchar()读取'
'(扔掉)。
 7 用函数scanf()读取整数时,会跳过前面的空格等,包括'
'及'	'。
 8 由于函数gets()不被推荐使用(容易造成存储越界访问),所有使用函数fgets()来读入一行字符串。
 9 符号常量N,如果定义为15(程序中是15 + 1),则会出现WA。也许是因为除了'
',还需要考虑字符串结束符号''。
10 题记:存储能省则省,只要不影响程序的简洁性。*/
11 #include<iostream>
12 #include<stdio.h>
13 #include<algorithm>
14 #include<iomanip>
15 #include<cmath>
16 #include<string.h>
17 //#define N 15+1
18 using namespace std;
19 int main()
20 {
21     int n;
22     //int i;
23     char a[20];
24     int nr,ny;
25     while(scanf("%d",&n)!=EOF && n)
26     {
27         getchar();               //
28         fgets(a,20,stdin);  //
29 
30         nr=0,ny=0;         //
31         int i;
32         for(i=0;i<n;i++)
33           {
34             //scanf("%s",&a[i]);
35             if(a[i]=='R')
36                 nr++;
37             else if(a[i]=='Y')
38                 ny++;
39           }
40         if((nr==7 && a[n-1]=='B')||(ny!=7 && a[n-1]=='L'))
41                 printf("Red
");
42 
43         else if((ny==7 && a[n-1]=='L')||(nr!=7 && a[n-1]=='B'))
44                 printf("Yellow
");
45 
46     }
47     return 0;
48 }
原文地址:https://www.cnblogs.com/Roni-i/p/7214019.html