zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    IOS 学习笔记(2) 视图UINavigationController
    [转] IOS中AppDelegate中的生命周期事件的调用条件
    IOS 学习笔记(1) 视图UIViewController
    IOS 单例模式的学习
    object-c 协议(Protocols)和代理(Delegation)的学习
    object-c 内存管理机制的学习
    Object-c Block的使用及说明
    KVO 的使用和举例
    魔豆电子相框
    魔豆应用开发傻瓜书——helloworld
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7214019.html
Copyright © 2011-2022 走看看