176k views
0 votes
There are N boxers competing in the boxing championship. The championship is categorized into 5 classes of weights A, B, C, D and F, where class A is for the players with weight between 66 and 75 kg, class B for player with weight between 76 and 85 kg, and so on till class F for players with weight from 106 Kg or more. Each player defines the class of his competition based on his initial weight. However, some player can do some effort before the competition to change their weight by moving to one class ahead or backward. For example, player can move from class C to class D by gaining some weights or from class C to B by losing some weights. They can do so without any condition. Given the initial weight of the players, write an algorithm that can predict the two classes with the maximum and minimum possible number of players as well as such expected numbers. Example 1: Input: array of initial weights Players 1 2 3 4 5 6 7 8 9 10 Class of Weight A C B C D D A B B D Output: The maximum number of players may exist in Class C with 8 players The minimum number of players may exist in Class F with 3 players b) Develop a python code to implement your algorithm

1 Answer

4 votes

To predict the two classes with the maximum and minimum possible number of players, use a dictionary to store the count of players for each class. Loop through the array of weights, determine the class for each weight, and increment the count for that class in the dictionary. Finally, find the classes with maximum and minimum counts and display the results.

To predict the two classes with the maximum and minimum possible number of players, we need to count the number of players in each class using the given initial weights. We can use a dictionary to store the count of players for each class. Loop through the array of weights, determine the class for each weight, and increment the count for that class in the dictionary. Finally, find the classes with maximum and minimum counts and display the results.

Python code:

weights = ['A', 'C', 'B', 'C', 'D', 'D', 'A', 'B', 'B', 'D']

count = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'F': 0}

for weight in weights:

if weight == 'A' or weight == 'B':

count['A'] += 1

elif weight == 'C' or weight == 'D':

count['C'] += 1

elif weight == 'F':

count['F'] += 1

max_class = max(count, key=count.get)

min_class = min(count, key=count.get)

print(f'The maximum number of players may exist in Class {max_class} with {count[max_class]} players')

print(f'The minimum number of players may exist in Class {min_class} with {count[min_class]} players')

User Kunal Roy
by
7.8k points