Bar

Description

According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?

The list of all alcohol drinks in Berland is: ABSINTHBEERBRANDYCHAMPAGNEGINRUMSAKETEQUILAVODKA,WHISKEYWINE

Input

The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.

Only the drinks from the list given above should be considered alcohol.

Output

Print a single number which is the number of people Vasya should check to guarantee the law enforcement.

Sample Input

Input
5
18
VODKA
COKE
19
17
Output
2

Hint

In the sample test the second and fifth clients should be checked.

 

题目很好理解,主要是输入的时候需要把握一下。

因为它输入时不确定是输入的 年龄即数字或者是字符串,所以要判定一下。我用的是 库函数中 string转化为 int 型的函数,如果是 数字则返回 数字;若是字符串,则返回 0;

注意,因为数字也可以为零,所以要做一个判定。这里是容易犯错的地方。

代码:

#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main()
{
    int n,i,k,x=0,y=0,num=0;
    int b[101];
    char s[101];
    string a[101],p;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s;                                
        k = atoi(s);                           //string转化为 int 型的函数,如果是 数字 则返回 数字
        if(k==0)
        {
            p=s;
            if(p=="0") {b[y]=0 ; y++;}        //判断是否是 数字 0 ;
            else {a[x]=p; x++;}
        }

        else { b[y]=k; y++;}
    }
    for(i=0;i<x;i++)
    {
        if(a[i]== "ABSINTH"||a[i]== "BEER"||a[i]== "BRANDY"||a[i]== "CHAMPAGNE"||a[i]== "GIN"||a[i]== "RUM"
           ||a[i]== "SAKE"||a[i]== "TEQUILA"||a[i]== "VODKA"||a[i]== "WHISKEY"||a[i]== "WINE")
         num++;
    }
    for(i=0;i<y;i++)
    {
        if(b[i]<18)
            num++;
    }
    cout<<num<<endl;
    return 0;
}

吃一堑长一智,不错!

posted on 2013-09-04 22:02  天梦Interact  阅读(372)  评论(0编辑  收藏  举报