-
-
Save LizardLeliel/10562547 to your computer and use it in GitHub Desktop.
Dalhousie problem letter A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This was problem A of the Dalhousie programming competiton. Of the four of five submissions I made, this was the only one that | |
#didn't suceed, and is also the most messiest and hardest to follow, but felt this showed some creative thinking | |
#The problem was that I had to figure out who won, based on how many problems the person solved, and if there's a tie, who did it in the shortest | |
#combined time of the problems. | |
#I would of had one line of input Which would be four numbers, representing the number of people in the competition, | |
#The number of problems there's going to be, what hour the competition started, and what minute the competition started. | |
#The second line is how many attempts to a problem there was from each person total | |
#And the rest of the lines each had 6 numbers seperated by spaces in them each, the first numberbeing the competitor's ID number (IE 1, 2, 3), | |
#the problem number he did, The hour he submitted it, the minute he submitted it, the moment he submitted it in seconds, | |
#and whether he passed of failed. | |
#An example would be | |
#2 4 12 0 | |
#3 | |
#1 2 12 10 10 fail | |
#2 2 12 11 13 pass | |
#1 2 12 15 20 pass | |
#And I would have to print who had the mosyt right, or who had the most right in the lowest ammount of total time. | |
#It had to be printed as "competitior >winner ID< wins by solbing >How many correct< ,in total time HH:MM:SS. | |
#This was just intializing a couple of things | |
specs = str(raw_input()).split(" ") | |
submissions = int(str(raw_input())) | |
pf = {"pass":True, "fail":False} | |
start = (int(specs[2])*60 + int(specs[3]))*60 | |
winnertrack = {} | |
for each in range(int(specs[0])): | |
winnertrack[int(each)+1]=(0, 0, []) | |
#For each student id, I created a tuple (similar to an array) for him of how many wins he had, his total time, and which solutions he finished, | |
#and then I would put it into a dictionary. All values were intialized as emptey values, for they were updated in the code below. | |
for each in range(int(submissions)): | |
submission = (str(raw_input()).split(" ")) | |
win = pf[submission[5]] | |
what = winnertrack[int(submission[0])][2] | |
what.append(submission[1]) | |
if win == True and int(submission[1]) not in winnertrack[int(submission[0])][2]: | |
winnertrack[int(submission[0])] = ((winnertrack[int(submission[0])])[0]+int(win), winnertrack[int(submission[0])][1]+((int(submission[2])*60 + int(submission[3]))*60+int(submission[4]))-start, what) | |
#After I have all the data stored in a preferable method, I then analyze it, although I initailze a few more values | |
#before I do the decision making on who won | |
thelist = [] | |
for each in winnertrack.values(): | |
thelist.append(each[0]) | |
thetimelist = [] | |
for each in winnertrack.values(): | |
thetimelist.append(each[1]) | |
#This frunction returns a string of time formatted to HH:MM:SS from seconds | |
def converttime(q): | |
hours = q//3600 | |
ms = q%3600 | |
minutes = ms//60 | |
seconds = ms%60 | |
if (hours+1)//10 == 0: hours = "0{0}".format(hours) | |
if (minutes+1)//10 == 0: minutes = "0{0}".format(minutes) | |
if (seconds+1)//10 == 0: seconds = "0{0}".format(seconds) | |
return "{0}:{1}:{2}".format(hours, minutes, seconds) | |
#And this is where I do the winner-decision making. This is also where the code breaks; although it will have correct output | |
#If there was a clear winner with no tie, wrong stats will be outputted if there was a tie | |
if thelist.count(max(thelist)) >= 2: | |
times = [x[1] for x in winnertrack.values() if x[0] == max(thelist)] | |
winner = max(times) | |
for each, competitor in enumerate(winnertrack.values()): | |
if competitor[1] == winner: print("Competitor {0} wins by solving {1} problems in total time {2}".format((each+1), int(competitor[0]), converttime(max(times)))) | |
else: | |
print("Competitor {0} wins by solving {1} problems in total time {2}".format(thelist.index(max(thelist))+1, int(max(thelist)), converttime(max(thetimelist)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment