-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcet_rank.py
121 lines (88 loc) · 2.57 KB
/
cet_rank.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import csv
class college:
def __init__(self, name, bname, s_max):
self.name = name
self.bname = bname
self.s_max = s_max
self.students = []
class student:
def __init__(self, name, rank, choices):
self.name = name
self.rank = rank
self.choices = choices
self.clg = " "
colleges = []
students = []
def is_filled(clg):
if(len(clg.students) == clg.s_max):
return True
else:
return False
def allocate(stud):
# True if allocated False if not
global colleges
for x in stud.choices:
for y in colleges:
if x == y.name:
if not is_filled(y):
y.students.append(stud)
stud.clg = y.name
return True
stud.clg = "Not allocated"
return False
# display students ranks and allocated colleges
with open("college.txt", "r+") as file:
rawdata = file.readlines()
for line in rawdata:
line = line.split()
colleges.append(college(line[0]+line[1], line[1], int(line[2])))
with open("students.txt", "r+") as file:
rawd = file.readlines()
for line in rawd:
line = line.split()
choices = [line[i] + line[i+1] for i in range(2, len(line), 2)]
# print(choices)
students.append(student(line[0], int(line[1]), choices))
# Allocation of seats
for s in students:
allocate(s)
print("Round One Results:")
for s in students:
print(str(s.rank)+" "+s.clg)
print("================================================")
fchoices = []
with open("round1.txt", "r+") as file:
rawd = file.readlines()
for line in rawd:
fchoices.append(int(line))
for i in range(len(students)):
# 0 means he rejects the seats
if(fchoices[i] == 0):
for y in colleges:
# print(y.students)
if students[i] in y.students:
y.students.remove(students[i])
students[i].choices.remove(students[i].clg)
students[i].clg = " "
# Second round allocation
for s in students:
if s.clg == " ":
allocate(s)
else:
s.clg=" "
for s in students:
if s.clg==" ":
allocate(s)
print("Round Two Results:")
for s in students:
print(str(s.rank)+" "+s.clg)
print("================================================")
print("Details of the colleges with their rankers:")
for y in colleges:
print(y.name)
if y.students == []:
print("No students elligible")
for i in y.students:
print(i.name, end=" ")
print(" ")
print(" ")