Bar (Codeforces 56A)
Tags: Implement, implementation

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: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE

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.

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

Sample Inputs:
5
18
VODKA
COKE
19
17

Sample Outputs:
2

Solution (Python):
def readln():
    return tuple(map(int, input().split()))
lst = 'ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE'.split(', ')
(n,) = readln()
ans = 0
for _ in range(n):
    inp = input()
    try:
        if int(inp) < 18:
            ans += 1
    except:
        if inp in lst:
            ans += 1
print(ans)

Solution (Python):
def main():
    from sys import stdin
    from math import gcd
    e = stdin.readline
    n = int(e())
    r = 0
    w = 'ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE'
    w = w.replace(',', '')
    w = w.split()
    for i in range(n):
        s = e().strip()
        if s in w:
            r += 1
        elif s.isdigit():
            if int(s) < 18:
                r += 1
    print(r)
main()

Solution (Python):
clients_number = int(input())
alcoholـdrinks = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
document = []
s = 0
for x in range(clients_number):
    z = input()
    try:
        document.append(int(z))
    except:
        if z in alcoholـdrinks:
            s += 1
for num in document:
    if num < 18:
        s += 1
print(s)