-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemClassifications.rb
More file actions
159 lines (149 loc) · 3.85 KB
/
ProblemClassifications.rb
File metadata and controls
159 lines (149 loc) · 3.85 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
require 'net\http'
require 'uri'
require 'set'
require_relative 'Problem'
require_relative 'PersonalList'
#http://vnoi.info/index.php?option=com_voj&task=classify&site=spoj&sort=1&limit=1000&limitstart=0
def getProblemsWithClassifications()
uri = URI.parse("http://vnoi.info/index.php?option=com_voj&task=classify&site=spoj&sort=1&limit=1000&limitstart=0")
subs = Net::HTTP.get(uri)
problemList = []
problemName = /<tr class='sectiontableentry[12]'>[ \t\n\r]*<td>[ \t\n\r]*.*[ \t\n\r]*<\/td>/
problemClassification = /<td>[ \t\n\r]*.*[ \t\n\r]*\(\d+\)[ \t\n\r]*<a href='#'/
eitherOr = /<tr class='sectiontableentry[12]'>[ \t\n\r]*<td>[ \t\n\r]*.*[ \t\n\r]*<\/td>|<td>[ \t\n\r]*.*[ \t\n\r]*\(\d+\)[ \t\n\r]*<a href='#'/
stuff = subs.scan(eitherOr)
flag = 0 #1 means we just found a problem. 2 means we just gave that problem a classification
#puts stuff
p
counter = 0
for str in stuff
stuff2 = str.scan(/[A-Z][A-Za-z0-9 -]*/)
if stuff2[0] =~ /[A-Z0-9]{2,}[ \t\n\r]*/
stuff2[0].strip!
problemList.insert(0, Problem.new(stuff2[0]))
flag = 1
elsif flag == 1
stuff2[0].strip!
problemList[0].classification = stuff2[0]
flag = 2
end
end
return problemList
end
def classifyYourProblems()
problemList = getProblemsWithClassifications()
yourACs = getYourACs(gets.chomp)
for problem in yourACs
for otherProblem in problemList
if problem.id == otherProblem.id
puts "You solved " + problem.id + ", which is a " + otherProblem.classification + " type of problem"
break
end
end
end
end
def howManyOfEachClass()
map = Hash.new()
problemList = getProblemsWithClassifications()
yourACs = getYourACs(gets.chomp)
for problem in yourACs
flag = 0
for otherProblem in problemList
if problem.id == otherProblem.id
flag = 1
if map.member?(otherProblem.classification)
map[otherProblem.classification] += 1
else
map[otherProblem.classification] = 1
end
break
end
end
if flag == 0
if map.member?("unclassified")
map["unclassified"] += 1
else
map["unclassified"] = 1
end
end
end
keys = map.keys;
keys.sort!
for key in keys
puts "You have solved #{map[key]} #{key} problems"
end
end
def classifyYourUnsolvedProblem()
yourACs = getYourACs(gets.chomp)
problemList = getProblemsWithClassifications()
file = File.new("masterList.txt")
allACs = []
while line = file.gets
allACs.push(line.chomp)
end
for thing in allACs
flag = 0
for item in yourACs
if (thing <=> item.id) == 0
flag = 1
end
end
if flag == 0
for problem in problemList
if problem.id == thing
puts problem
flag = 1
end
end
if flag == 0
puts thing + " is an unclassified problem"
end
end
end
end
def sortUnsolvedProblemsByClassification(unsolvedProblemList, problemsWithClassifications)
map = Hash.new()
for problem in unsolvedProblemList #these are just strings of the ID
flag = 0
for problemWithClass in problemsWithClassifications #these are problems
if problem == problemWithClass.id
flag = 1
classification = problemWithClass.classification
if map.member?(classification)
map[classification].push(problem)
else
map[classification] = Array[problem]
end
end
end
if flag == 0
classification = "unclassified"
if map.member?(classification)
map[classification].push(problem)
else
map[classification] = Array[problem]
end
end
end
return map
end
=begin
for problem in problemsWithClassifications
index = unsolvedProblemList.index(problem.id)
if index != nil
classification = problemsWithClassifications[index].classification
if map.member?(classification)
map[classification].push(problem.id)
else
map[classification] = Array[problem.id]
end
else
if map.member?("unclassified")
map["unclassified"].push(problem.id)
else
map["unclassified"] = Array[problem.id]
end
end
end
puts map
=end