In this HackerRank The Minion Game problem solution we have a gameplay and in this game all the players given the same string and we need to make substrings using the letters of the string with consonants and vowels. we need to predict the winner.
HackerRank The Minion Game in python problem solution
import string
word = input().rstrip()
length = len(word)
vowels = {i : False for i in string.ascii_uppercase}
for i in "AEIOU":
vowels[i] = True
stuart_points = 0
bob_points = 0
for start in range(length):
if vowels[word[start]]:
bob_points += length - start
else:
stuart_points += length - start
if stuart_points > bob_points:
print("Stuart", stuart_points)
elif stuart_points < bob_points:
print("Kevin", bob_points)
else:
print("Draw")
Second solution
s = raw_input ()
sc = [0, 0]
for i in xrange (len (s)):
sc [s [i] in 'AEIOU'] += len (s) - i
if sc [0] > sc [1]: print 'Stuart', sc [0]
elif sc [1] > sc [0]: print 'Kevin', sc [1]
else: print 'Draw'
0 Comments