Skip to content

Commit 7fe9fb1

Browse files
author
matthias
committed
2 parents a3484ae + 9432149 commit 7fe9fb1

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Codeforces Parser v1.4.1
1+
Codeforces Parser v1.5
22
=================
33

44
Summary
@@ -11,15 +11,15 @@ This is a python program that parses the sample tests from the contest problem p
1111
You can also find this article here, [http://codeforces.com/blog/entry/10416](http://codeforces.com/blog/entry/10416)
1212

1313
### Example:
14-
`./parse.py contest_number (e.g. ./parse.py 464)`
14+
`./parse.py contest_number (e.g. ./parse.py 513)`
1515

16-
Where `464` is the contest number, not the round number! Check the URL of the contest on your browser, that is the number you are supposed to use.
16+
Where `512` is the contest number, not the round number! Check the URL of the contest on your browser, that is the number you are supposed to use.
1717

1818
### Effect:
1919

20-
##### What will happen, for example, if `./parse.py 464` is executed?
20+
##### What will happen, for example, if `./parse.py 512` is executed?
2121

22-
1. Directories `464/A`, `464/B`, `464/C`, `464/D` and so on are created depending on the contest number of problems.
22+
1. Directories `512/A`, `512/B`, `512/C`, `512/D` and so on are created depending on the contest number of problems.
2323
2. For each problem, `main.cc` is copied and renamed to the problem letter to the corresponding directory. **You can put the path of your usual template in `parse.py:20`**.
2424
3. Problem page is downloaded from Codeforces website, and parsed. Sample input/output files are generated, e.g. `input1`, `output1`, `input2`, `output2` and so on. You can create your own test cases after that, just keep the same naming format as others test cases.
2525
4. A script `test.sh` is generated. You can use it to compile and run the sample tests after you finish coding. Just run `./test.sh` in the problem directory.
@@ -28,6 +28,7 @@ Where `464` is the contest number, not the round number! Check the URL of the co
2828

2929
1. Compilation: `g++ -g -std=c++0x -Wall $DBG main.cc`. **You can change the compile options in `parse.py:21`**. Variable $DBG is set to -DDEBUG if you start "./test.sh -d", otherwise it is empty. This allows for compilation with and without debug macros.
3030
2. Run each sample tests on your program (`a.out`), and check the output by `diff`. If it's correct, print **Accepted**, or else print the sample test that went wrong.
31+
3. Please note that for problems with multiple correct answers it might say that your output is incorrect.
3132

3233
### Collaborators and Versions:
3334

@@ -38,6 +39,9 @@ Where `464` is the contest number, not the round number! Check the URL of the co
3839
If you have any suggestions and/or bugs drop a message!
3940

4041
##### Versions Changes:
42+
+ **1.5:**
43+
Added debug flag (-d) to enable DEBUG macro (read above for details).
44+
Fixed problems parsing for problem names that are not called A, B, etc. Such as A1, A2..
4145
+ **1.4.1:**
4246
Minor fixes, such as typos, bugs and special characters handling.
4347
+ **1.4:**

parse.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
MY_OUTPUT='my_output'
2929

3030
# Do not modify these!
31-
VERSION='CodeForces Parser v1.4.1: https://github.com/johnathan79717/codeforces-parser'
31+
VERSION='CodeForces Parser v1.5: https://github.com/johnathan79717/codeforces-parser'
3232
RED_F='\033[31m'
3333
GREEN_F='\033[32m'
3434
BOLD='\033[1m'
@@ -90,6 +90,7 @@ def __init__(self, contest):
9090
self.start_contest = False
9191
self.start_problem = False
9292
self.name = ''
93+
self.problem_name = ''
9394
self.problems = []
9495
self.problem_names = []
9596

@@ -98,7 +99,7 @@ def handle_starttag(self, tag, attrs):
9899
self.start_contest = True
99100
elif tag == 'option':
100101
if len(attrs) == 1:
101-
regexp = re.compile(r"u'[A-Z]'")
102+
regexp = re.compile(r"u'[A-Z].*'")
102103
string = str(attrs[0])
103104
search = regexp.search(string)
104105
if search is not None:
@@ -109,20 +110,23 @@ def handle_endtag(self, tag):
109110
if tag == 'a' and self.start_contest:
110111
self.start_contest = False
111112
elif self.start_problem:
113+
self.problem_names.append(self.problem_name)
114+
self.problem_name = ''
112115
self.start_problem = False
113116

114117
def handle_data(self, data):
115118
if self.start_contest:
116119
self.name = data
117120
elif self.start_problem:
118-
self.problem_names.append(data)
121+
self.problem_name += data
119122

120123
# Parses each problem page.
121124
def parse_problem(folder, contest, problem):
122125
url = 'http://codeforces.com/contest/%s/problem/%s' % (contest, problem)
123126
html = urlopen(url).read()
124127
parser = CodeforcesProblemParser(folder)
125-
parser.feed(html.decode('utf-8').encode('utf-8')) # Should fix special chars problems.
128+
parser.feed(html.decode('utf-8'))
129+
# .encode('utf-8') Should fix special chars problems?
126130
return parser.num_tests
127131

128132
# Parses the contest page.
@@ -194,7 +198,7 @@ def generate_test_script(folder, num_tests, problem):
194198
def main():
195199
print (VERSION)
196200
if(len(argv) < 2):
197-
print('USAGE: ./parse.py 435')
201+
print('USAGE: ./parse.py 512')
198202
return
199203
contest = argv[1]
200204

0 commit comments

Comments
 (0)