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

Автор sayuan, 12 лет назад, По-английски

https://github.com/sayuan/CodeforcesRunner

This is a simple tool which can run sample tests easier.

Currenty, it support only 4 languages: c++, c, java, python. However, it coule be expand very easily and the source code is really short. I haven't added other languages just because I don't have the enviroment for verify.

This tool is only verified on Linux now, but I think it could be run on other platforms too, although it maybe need a little modify.

Again. Please feel free to fork and any suggesions are welcome. :)

08/13 update

Now this tool can download the sample tests automatically:

$ cf.py -c 198 -p A

You can also download the whole contest:

$ cf.py -c 198

Please see the project page for more detail. Thanks.

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

»
12 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Very nice! I, too, use something similar, though Make-based. It's also nice to see that compiler flags are the same as on CF. You could add -m32 to C and C++ to force 32-bit compilation on 64-bit platforms (the CF system is 32-bit).

One concern might be that input and output are too slow to type repeatedly. Even if you prepare an empty file with these markers, it takes time to position the cursor for insertion. There's also a possibility that a test case will contain input or output. I'm not sure what would be a better alternative for separation (I just use empty lines, which are easy to type).

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Thank you for your recommandatiom. I will add the option -m32 later.

    The input and output texts are part of sample tests in the problem, you can copy & paste it directly from the problem page, see here: http://codeforces.net/problemset/problem/198/A

    Sometimes, I will add test cases which generate by myself. In this case, I always copy & paste the existing test and modify it.

    Test cases contain input or output is a big trouble to this program. Hope this will not happen forever! Maybe we need another tool to download and parse the problem page? :p

    • »
      »
      »
      12 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Haha, indeed, you can copy the whole tests section at once, and input/output will be in place! It didn't occur to me because I use the Russian interface.

    • »
      »
      »
      12 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      In the HTML source of the problem description page sample inputs and outputs are inside divs of classes <div class="input"> and <div class="output">. So possibly you could just parse this page and get the correct samples without trouble even if they contain words input and output.

      • »
        »
        »
        »
        12 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

        I am not sure the anonymous has the permission to read the problem during the contest. However, I will check it during the next contest. If so, I will try to implement it. Thank you.

        update on Aug 7 Ok, now I am sure anonymous has the permssion to read the problem during the contest.

»
12 лет назад, # |
Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

As It's tool for CodeForces where checkers are friendly, I think it should allow additional whitespaces (e.g to print array as

for(int i = 0; i<n;++i){
    cout<<a[i]<<' ';
}

). I've add pull request.

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Already merged. Thank you for your contribution.

    I think it is always better to have the same behavior with Codeforces judge. However, after searhing all articles abort rules, I still can't find the detail of how the judge doing.

    By the way, I currently plan to add preferences file to this tool. All compile and run options will move to that file, which is generated by this tool if it doesn't exist. I think the strict option should move to preferences file too. How to you think?

    • »
      »
      »
      12 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

      About how it works: A programm called checker runs and gets correct answer, participiants output and input. It returns PE or WA or AC. There are some std checkers for sequence of integer, seq of tokens, yes/no, doubles. You may see std checkers in testlib code.

      I think, it should be possible to change this setting from problm to problem. Btw, It's OK to add default setting, but I don't think it's useful.

»
12 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Maybe this tool should always print all testcases because some problems may support different outputs. In this case you may see WA on test 1 and be not able to see results of other tests

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    This tool is already print all testcases. However, when the answer incorrect, this message will print: "press enter to continue or to leave." and this process continue when you press enter.

»
12 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Wouldn't it make more sense to put the output information for each test case after the "== Case #X:" heading? For example:

=== Case #1: AC (85 ms) ===

output: 2

=== Case #2: WA (83 ms) ===

output: 2

answer: 3

=== Case #3: RE (95 ms) ===

output: Exception in thread "main" java.lang.Exception at A.(A.java:12) at A.main(A.java:18)

answer: 0

Just a suggestion :)

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Display the result at the top has a major disadvantage, you can't see the output immediately. This may increase the debug difficulty, since you only see the output after the process exit.

    However, add another marker before each case is ok. Any idea?

»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I think if you can create a plugin for the IDE (ex: codeblock, eclipse, ...), it will be more convenient, faster and easier to use ;-)

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    It is so hard to create plugins for each IDE. However, most of the modern editor has customized hotkeys, so you can just press a key to execute this script.

    For instance, I use VIM as my editor and added this line in my $VIMRC: nmap <F8> :!cf.py "%:t"<CR>.

»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Which version of python do you use? (2.7 or 3.3)

  • »
    »
    12 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Currently, I am using Python 2.7, and I hava no idea what going to happen if you run this tool under Python 3.x.

    I will try to use syntaxes and libraries which both valid in Python 2.6 ~ 3.x, but I can't guarantee it. If I have to decide to only support some versions of Python, Python 2.7 is preferred.

»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Your logo:







»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

(For the new version): The link can be more simple (Such as 198A instead of http://codeforces.net/problemset/problem/198/A) :-)

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thank you. Actually, I forgot to update the usage of the newest version in this post. Now you can just specifiy the contest_id (and problem_id) to download the sample tests. Please see the post on the top.

»
12 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

I downloaded the newest version and try to check my solution. I got this error

http://ideone.com/bRPIB

Help me, please!

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    Since the gcc(& g++) has the option -m32, you need some 32-bits libraries.

    Using apt to install g++-multilib might solve your problem. (also install gcc-multilib for gcc).

    Another solution is remove the option -m32 if you don't need 32-bits compilation. Please modify compile_cmd in the [.cpp] section in the cf.conf file.

»
11 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

Nice plugin. Please update the link (distinct github username): https://github.com/sayuan/CodeforcesRunner

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    I forgot to update this link after I change the user name. Now it is fixed. Thank you for your remind.