Guest User

Google Codejam 2016 Round 3 Problem A

a guest
Jul 27th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. # source: https://code.google.com/codejam/contest/3224486/dashboard#s=p0
  2. # finished in a bit under 25 minutes
  3.  
  4. import sys
  5.  
  6. def main():
  7.     filename = sys.argv[1]
  8.     with open(filename) as f:
  9.         num_inputs = int(f.readline())
  10.         for i in range(num_inputs):
  11.             score = 0
  12.             problems = []
  13.             moods = f.readline()
  14.             for j in range(len(moods)):
  15.                 # the assumption is that you'll only request problems that're the same mood that the grader is in
  16.                 # reason being that you can receive a maximum of 10 points and a minimum of 5,
  17.                 # whereas for the other mood it'll be a max of 5 and a min of 0
  18.                 if len(problems) == 0:
  19.                     problems.append(moods[j])
  20.                 elif len(problems) >= len(moods) - j:
  21.                     if problems[-1] == moods[j]:
  22.                         score += 10
  23.                     else:
  24.                         score += 5
  25.                     problems.pop()
  26.                 elif problems[-1] == moods[j]:
  27.                     score += 10
  28.                     problems.pop()
  29.                 else:
  30.                     problems.append(moods[j])
  31.             print('Case #', i+1, ': ', score, sep='')
  32.  
  33. if __name__ == '__main__':
  34.     main()
Add Comment
Please, Sign In to add comment