### Блог пользователя johnathan79717

Автор johnathan79717, 4 года назад, ,

Many thanks to brunoja. He is the main contributor now. Please try it out and give us feedback. You're also welcome to fork the project or join us as a collaborator.

https://github.com/johnathan79717/codeforces-parser

# Codeforces Parser v1.4.1

## Summary

Codeforces is a website for competitive programming. It holds contests, so-called Codeforces Rounds, about every week.

This is a python program that parses the sample tests from the contest problem pages. For each problem, it generates the sample input/output files and a shell script to run sample tests.

### Example:

./parse.py contest_number (e.g. ./parse.py 464)

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.

### Effect:

##### What will happen, for example, if ./parse.py 464 is executed?
1. Directories 464/A, 464/B, 464/C, 464/D and so on are created depending on the contest number of problems.
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.
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.
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.
##### What will happen if ./test.sh is executed?
1. Compilation: g++ -g -std=c++0x -Wall main.cc. You can change the compile options in parse.py:21.
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.

### Collaborators and Versions:

##### List of CodeForces Collaborators:

If you have any suggestions and/or bugs drop a message!

##### Versions Changes:
• 1.4.1: Minor fixes, such as typos, bugs and special characters handling.
• 1.4: Changed how the parser gets the problems. During the competitions the page is slightly different. Fixed some invalid character on input and output causing the script to crash. Forcing a new line on the input/output if there is none. Fixed some line number information in this README file.
• 1.3: Some minor fixes and code organizing. Also fixed some typos. Removed the sample from default input and output files.
• 1.2: Fixed some typos and constants. Fetching contest info, printing contest name and problem names. The contest may now have more or less than 5 problems, it will auto detect. The script will now generate the template with the problem letter. Fixed test cases fetching. The script was stopping for escaped html characters, such as '&lt'. Fixed script to work with python 3.
• 1.1: Cleaner generation of the test script, now it auto detects the test cases, making you able to create your own cases. Echo color output, for accepted we get a green message, otherwise it is red. Added the time measurement for running the test cases. For the runtime error case, it now outputs the input case. Created some constants, such as compile options. These user modifiable constants should be easily spotted at the first lines of the python script.
• 1.0: Initial Version.
##### Todo, Bugs & Troubleshootings:
• In OS X it is necessary to install the gnu-time to measure time.
• This parser currently works only on Unix OSes. If you want to add Windows/Other support let us know.

•
• +63
•

 » 4 года назад, # | ← Rev. 2 →   +3 Hi! Thanks for this, really helpful :). In the test.sh script there is a line before running your code: rm sample_*. That is deleting the sample cases before running them, is it correct?Also, you may want to change -std=c++11 to -std=c++0x, it works for older gcc versions (like mine, gcc 4.6).
•  » » 4 года назад, # ^ | ← Rev. 3 →   0 Thanks, that's a stupid mistake. I've removed it. Also changed to -std=c++0x. Thanks a lot for the suggestion :)
•  » » » 4 года назад, # ^ | ← Rev. 4 →   +3 it is better to replace on "rm -R my_output{0}\n"
•  » » » » 4 года назад, # ^ |   0 Your right! That's what I had in mind when I wrote that line I guess :P Thanks a lot.
•  » » » » 4 года назад, # ^ | ← Rev. 2 →   +3 You should not remove the a.out! Also add a -R to the rm command, otherwise it will stop the script (the first time you run it, there isn't an output file yet..).
•  » » » » » 4 года назад, # ^ |   +3 Oh, of course, you are right)
•  » » » » » 4 года назад, # ^ |   0 Thanks again... I really should have tested thoroughly every time before commit and push. Nice to have you guys helping.
 » 4 года назад, # |   +3 from where we can download this?and can it run under windows or it needs Linux? and thanks for your work, it looks great :D
•  » » 4 года назад, # ^ |   0 The project is at https://github.com/johnathan79717/codeforces-parserYou can run git clone https://github.com/johnathan79717/codeforces-parser.git or there's a button at the bottom right corner of the page that allows you to download a zip file.We haven't try it on windows. You're welcome to try it out and make a windows version.
 » 4 года назад, # |   +3 Hi, I can not use it for proxy authentication? Can you add some support for that? As you are using urlopen for downloading the problem statement, Urlopen does not allow it to have a proxy with user authentication. Do you have some workaround for this?
•  » » 4 года назад, # ^ |   0 Hi, could you elaborate in what situation do you need proxy authentication? Thanks. This may work, but I haven't tried it yet.
•  » » » 4 года назад, # ^ |   +3 Hi, I usually use internet on the linux pcs installed in our institute labs, So I need to use proxy authentication for that purpose. For now I have kind of patched the things by using FancyURLopener class in the urrlib. I will try to find a good solution for it. I saw your link, it was quite similar to what I was doing, Thank you
 » 4 года назад, # |   +5 I think it would be fantastic if Codeforces provides an API to obtain the test cases to not have to parse the entire HTML.
 » 4 года назад, # |   +16 What is the license of your code? I have my own tester and I would like to use your parser. :)
•  » » 4 года назад, # ^ |   +9 You can use it however you want :)
•  » » » 4 года назад, # ^ |   +31 This license is called WTFPL, just for you to know.
•  » » » » 4 года назад, # ^ |   +11 WAGL: What A Great License.
•  » » » 4 года назад, # ^ |   +8 Ok, Thanks!
 » 4 года назад, # |   +3 Hi! I just merged the branch I was using with some fixes and I thought it might be good to announce it here :). The current version is the 1.4.1. Thanks!
•  » » 4 года назад, # ^ |   +5 Good Job!
 » 3 месяца назад, # |   0 Oh, this is great! Thank you)
 » 6 недель назад, # |   0 Nice! Trick for Windows users: 1.download git 2.change #!/usr/bin/python -> #!C:/YourPath/python.exe and a.out -> a.exe in script 3.keep playing 3d pinball space cadet:) PS: time command doesn't work properly in this shell