HACKER RANK Python Strings Challenges - The Minion Game Solution.'Py'

Python Strings Challenges - The Minion Game Solution
Problem Statement
Kevin and Stuart want to play the 'The Minion Game'.
Bob is the match referee. Bob's task is to declare the winner and ensure that no rules are broken.
Stuart is Player 1 and Kevin is Player 2.
About Game

Rules
The game is a two player game. Players are given a string S.
Both the players have to make words using the letters of string S.
Player 1 has to make words starting with consonants.
Player 2 has to make words starting with vowels.
Game ends when both players have made all possible substrings. 
Scoring
A player gets +1 Point for each occurence of the word in the string S.
Example:
If string S = BANANA
Word made by Player 2 = ANA
'ANA' is occuring twice in 'BANANA'. Hence, Player 2 will get 2 Points.

For better understanding, see the image below:
Your task is to help Bob.
Input Format
Single line containing string S.
Note: String S contains only capital alphabets [A-Z].
Constraints
0<len(S)106
Output Format
Print the name of the winner along with the total score.
If the game is draw, print Draw.
Sample Input
BANANA
Sample Output
Stuart 12

Note:

I would like to suggest mentioning that the vowels here are defined as AEIOU

(since Y is sometimes considered a vowel, but not in this problem).

Solution:

from collections import defaultdict
import sys
if sys.version_info[0]>=3: raw_input=input
k=[0,0]
s=raw_input().strip()
for i,c in enumerate(s): k[c in 'AEIOU']+=len(s)-i
if k[0]>k[1]:
 print('Stuart %d'%k[0])
elif k[0]<k[1]:
 print('Kevin %d'%k[1])
else:
 print('Draw')

Thanks for Visiting, Hope this helps you....

Copyright © 2015 HackerRank.
All Rights Reserved

Comments

  1. interesting blog. It would be great if you can provide more details about it. Thanks you




    Minion Phone Case

    ReplyDelete
    Replies
    1. Thanks a lot Martinez....
      And, here after the posts will be more clear with more details....

      Delete

Post a Comment

Popular Posts