In python Please
The general elections are over, now is the time to count the votes
and find out who will take the reins of this country. There are c
(2 <= c <= 6) candidates and m (1 <= m <= 74) voting
regions. Given the number of votes for each candidate in each
municipality, determine which candidate is the winner (the one with
the most votes). Input Format The first line of input contains an
integer T (1 <= T <= 100), the number of test cases that
follow. Each test case begins with two integers c and m that denote
the number of candidates and regions respectively. The next m lines
each contain n integers V1, V2, ..., Vn (0 <= Vi <= 1000) the
number of votes for candidate c. Constraints c (2 <= c <= 6)
candidates m (1 <= m <= 74) (0 <= Vi <= 1000) the
number of votes for candidate c Output Format For each test case,
print the winning candidate on one line. You can assume that the
winner is unique.
Here is th python code:
NOTE: Here is the python code, when you run to update the filename = 'candidatesList.txt' with the correct filename which contains the test cases
def main():
try:
filename = 'candidatesList.txt'
f = open(filename, 'r')
test_cases = int(f.readline().strip())
for test in range(test_cases):
cand_region = f.readline().strip().split()
candidatesList, regions = int(cand_region[0]),
int(cand_region[1])
candidate_votes = [0] * candidatesList
for region in range(regions):
vote_line = f.readline().strip().split()
votes = [int(v) for v in vote_line]
for i in range(candidatesList):
candidate_votes[i] += votes[i]
winner_candidate = candidate_votes.index(max(candidate_votes)) +
1
print(winner_candidate)
except:
print('Error: File: {} not found.'.format(filename))
main()
#********I hope you find this helpful and please do UPVOTE as to appreciate my effort..THANKS:)******
Get Answers For Free
Most questions answered within 1 hours.