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).
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.
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 stringS .
Both the players have to make words using the letters of stringS .
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.
Rules
The game is a two player game. Players are given a string
Both the players have to make words using the letters of string
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 getsS .
Example:
If stringS = BANANA
Word made by Player 2 = ANA
'ANA' is occuring twice in 'BANANA'. Hence, Player 2 will get
For better understanding, see the image below:
A player gets
+1
Point for each occurence of the word in the string Example:
If string
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: StringS contains only capital alphabets [A-Z].
Note: String
Constraints
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')
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
All Rights Reserved
interesting blog. It would be great if you can provide more details about it. Thanks you
ReplyDeleteMinion Phone Case
Thanks a lot Martinez....
DeleteAnd, here after the posts will be more clear with more details....