Giter Club home page Giter Club logo

codeforces-parser's Introduction

Codeforces Parser v1.5.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.

You can also find this article here, http://codeforces.com/blog/entry/10416

Installation

Example:

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

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.

Effect:

What will happen, for example, if ./parse.py 512 is executed?
  1. Directories 512/A, 512/B, 512/C, 512/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 $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.
  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.
  3. Please note that for problems with multiple correct answers it might say that your output is incorrect.

Collaborators and Versions:

List of CodeForces Collaborators:
  • johnathan79717
  • brunoja
  • [Matthias Kauer (mini addition)] If you have any suggestions and/or bugs drop a message!
Versions Changes:
  • 1.5.1: Minor bug fixes related to Python 2 vs Python 3. Makes the template file to use the proper language extension.
  • 1.5: Added debug flag (-d) to enable DEBUG macro (read above for details). Fixed problems parsing for problem names that are not called A, B, etc. Such as A1, A2..
  • 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.

codeforces-parser's People

Contributors

brunojadami avatar jakobkogler avatar joaquingx avatar johnathan79717 avatar ldt116 avatar matthiaskauer avatar smilitude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeforces-parser's Issues

CodeForces blocks default python user agent

Recently, CF began blocking the default urllib2 python user agent (at least for me). This means that requests made using this script fail with a "Forbidden 403" error.

Without looking to see if CF has a preferred way of interacting, I'll note that manually changing the user agent allows this simple script to continue working.

./test.sh error which said "cat: time.out: No such file or directory"

which: no time in (/home/gengchen/.autojump/bin:/home/gengchen/.autojump/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
./test.sh: line 26: -o: command not found
cat: time.out: no such file or directory
Sample test #1: Runtime Error
....

I run which time, it turned out:
time: shell reserved word

when i deleted the content related to "time", it worked.

OS: Manjaro 17.0.5 Gellivara
Kernel: x86_64 Linux 4.9.50-1-MANJARO
Shell: zsh 5.4.2

Considering separate out input/output generation from code template generation

Thank you for developing this! I have a suggestion:

Many codeforces users use other languages like Java, Python and Ruby. They don't really care about care about C/C++. Many users who use C or C++ have their own setup mechanisms. Additionally in languages like Java and Scala, you cannot have class or filenames starting with a number.

It is best to separate this into 2 concerns. Something like download-tests.py to simply download the input/output files and setup-template.py to setup code template. I think most users of this really like the ability to download the test cases easily.

Support for other languages (Go, Rust)

Hi,
I'm interested in adding support for additional languages. This should just require changing the build executable. Since these languages evolve fast, I'd maybe add a version check as well.

Are you interested in merging something like that?
If so, my main question is what the interface should look like. I'd leave C++ as a default. Then we could activate another language from the test.sh script via CLI switch, say "-l go", or "-l rust". Or we create an environment variable, say CODEFORCES_PARSER_LANG to achieve a similar behavior.
What do you think?

Best,
Matthias

Request for license

Hi, I was looking for creating a script build for archlinux and I need to know the LICENSE of this package.

Cheers,
Joaquin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.