-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathstring_minions.py
104 lines (76 loc) · 2.14 KB
/
string_minions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
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: banana.png
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)
"""
# Enter your code here. Read input from STDIN. Print output to STDOUT
string = raw_input()
word = list(string)
def occurrences(string, sub):
count = start = 0
while True:
start = string.find(sub, start) + 1
if start > 0:
count+=1
else:
return count
vow = list('AEIOU')
kv = set()
sc = set()
kwl = set()
swl = set()
swlp = 0
kwlp = 0
for i in word:
if i in vow:
kv.add(i)
else:
sc.add(i)
for i in xrange(len(word)):
for j in range(i,len(word)):
if word[i] in kv:
kwl.add(string[i:j+1])
# print '% %',(i,j+1)
else:
swl.add(string[i:j+1])
#For points
for i in swl:
swlp = swlp+occurrences(string,i)
for i in kwl:
kwlp = kwlp+occurrences(string,i)
if swlp > kwlp:
print 'Stuart',swlp
elif kwlp > swlp:
print 'Kevin',kevin
else:
print 'Draw'