Translate

Views

Wednesday, March 26, 2025

Shortest Solution UVA 11629 - Ballot evaluation

 

  Problem  VerdictLangTimeBestRankSubmit Time
 | discuss11629 - Ballot evaluation AcceptedPython0.2800.00014092 hours ago


def f(total, com, rs):
    if com == ' <= ':
        return total <= rs
    elif com == ' >= ':
        return total >= rs
    elif com == ' = ':
        return total == rs
    elif com == ' < ':
        return total < rs
    else:
        return total > rs

p, q = map(int, input().split())
d = {}
for _ in range(p):
    x, y = input().split()
    d[x] = int(float(y)*10)
   
cnt = 1
b = [' < ', ' > ', ' <= ', ' >= ', ' = ']
for _ in range(q):
    a = list(input().split(' + '))
    com = None
    rs = 0
    for c in b:
        if (c in a[-1]):
            rs = int(a[-1].split(c)[1])*10
            a[-1] = a[-1].split(c)[0]
            com = c
    total = 0  
    for x in a:
        total += d[x]
    if f(total, com, rs):
        print(f"Guess #{cnt} was correct.")
    else:
        print(f"Guess #{cnt} was incorrect.")
    cnt += 1

No comments: