- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to find score and name of winner of minion game
Suppose there are two players Amal and Bimal. They are playing a game. The game rules are as follows −
Both players have a same string s.
Both of them have to make substrings using the letters of s.
Bimal has to make words starting with consonants.
Amal has to make words starting with vowels.
The game will end when both players have made all possible substrings.
Now the scoring criteria is like: a player gains 1 point for each occurrence of the substring in the string s. We have to find winner of this game and his score.
So, if the input is like s = "BANANA", then the output will be Bimal, 12 because
|Word : BANANA|
|Total 9||Total 12|
To solve this, we will follow these steps −
- vowels := a set of vowels
- p1 := 0
- p2 := 0
- for each index i and character c in word, do
- if c is a vowel, then
- p2 := p2 + size of word - i
- p1 := p1 + size of word - i
- if c is a vowel, then
- if p1 > p2, then
- return 'Bimal', p1
- otherwise when p2 > p1, then
- return 'Amal', p2
- return 'Draw'
Let us see the following implementation to get better understanding
def solve(word): vowels = set('AEIOU') p1 = 0 p2 = 0 for i, c in enumerate(word): if c in vowels: p2 += len(word) - i else: p1 += len(word) - i if p1 > p2: return 'Bimal', p1 elif p2 > p1: return 'Amal', p2 else: return 'Draw' word = "BANANA" print(solve(word))
- C++ Program to find winner name of stick crossing game
- Program to find winner of stone game in Python
- C++ program to find winner of card game
- Program to find winner of array removal game in Python
- Program to find winner of number reducing game in Python
- C++ program to find winner of cell coloring game
- C++ program to find winner of ball removal game
- C++ Program to find winner of unique bidding game
- Program to find the winner of an array game using Python
- Program to find winner of a rower reducing game in Python
- Program to find winner of a rower breaking game in Python
- Program to find maximum score of brick removal game in Python
- Program to find winner of a set element removal game in Python
- C++ Program to find maximum score of bit removal game
- C++ program to find winner of typing game after delay timing