-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCS_CODEVITA.py
85 lines (56 loc) · 1.54 KB
/
TCS_CODEVITA.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
inp = list(map(int, input().split()))
C = inp[0] # no. of college
N = inp[1] # no. of students
C_no_of_seats = list(map(int, input().split()))
N_student = []
for i in range(0 , N , 1):
temp = input().split(",")
N_student.append(temp)
N_student2 = []
def convert(N_student):
temp = N_student
id1 = temp[0]
id1 = int(id1[2])
per = float(temp[1])
per = int(per*100)
choice1 = temp[2]
choice1 = int(choice1[2])
choice2 = temp[3]
choice2 = int(choice2[2])
choice3 = temp[4]
choice3 = int(choice3[2])
N_student2.append([id1,per,choice1,choice2,choice3])
return
for i in range(0 , N , 1):
temp = N_student[i]
convert(temp)
N_student = N_student2
# take second element for sort
def takeSecond(elem):
return elem[1]
# sort list with key
N_student.sort(key=takeSecond)
N_student.reverse()
def check(C_no_seats , detail):
choice1 = detail[2]-1 # choice shows college no.
choice2 = detail[3]-1
choice3 = detail[4]-1
if C_no_seats[choice1] > 0:
C_no_seats[choice1] -= 1
return detail[2]
elif C_no_seats[choice2] > 0:
C_no_seats[choice2] -= 1
return detail[3]
elif C_no_seats[choice3] > 0:
C_no_seats[choice3] -= 1
return detail[4]
return 0
output = []
for i in range(0 , N , 1):
temp = N_student[i]
result = check(C_no_of_seats , temp)
id = temp[0]
if result != 0:
x = "Student-"+str(id)+" C-"+str(result)
output.append(x)
print(output)