欢迎访问


How to Add New Questions

By: Homecox. 08/15/2013

This article discusses how to add new OJ questions.

A new OJ question submission should include these information:

  1. Title (to appear on OJ)
  2. Description (to appear on OJ)
  3. More detailed description (optional)
  4. Author: how you prefer to be referred to.
  5. Source: where this problem comes from.
  6. Type: classification of the problem, e.g., tree, stack, dynamic programming, divide and conquer etc.
  7. Source code: in C++, Java or both. The source code should use OJ API and comply with the format below. Please use 4 spaces for indentation.

Add test cases

One can add test cases, this is simple. Just include small and large test cases in plain text file. Each test case on one line. Specify your notations. Please do make good test cases.

Add entire test files

Another option is to add entire test files. This involves more work. It can take 30 to 60 minutes for one question (including C++ and Java) using the Homecox OJ read/dump/equal API: OJ class in C++ (OJ.cpp, API) and Java (OJ.java, Test.java, API). Note OJ.java and OJ.cpp are released under the 3-clause BSD license.

This is much faster than when I worked on the first question, which took me 5 hours, and most time were spent on writing input/output/compare functions for different data types.

An example using the "climbing stairs" question (for its simplicity):

  • C++ test file: Test.cpp
  • Java test file: Test.java
  • and (optionally) test cases output out.txt (this can be converted to one line delimited by "|", using linux command: tr '\n' '|' < out.txt)

Explanation

For both Test.cpp and Test.java, the top part is "class Solution", this is the same as user submitted code. You can use either correct algorithm or a place holder, but correct function signature is required.

The second part is "class OJ". This includes read/dump/equal functions needed for the input/output types of this question. It could include the entire OJ class. However, to make it succinct, just copy and paste relevant functions here.

The last part is "class Test". Place test cases in constructor Test(). In function test(), change input/output data types. Finally if provide the correct algorithm, put it in the "Correct algorithm for the question" section. The relevant sections that need change are labeled 1) to 4) in the code.

Test.cpp and Test.java should compile and can execute to generate identical output in the desired format. For example, both here will generate this output:

Note there are 2 ways of providing output for test cases:

  1. As a string and read it in (like here), which is more efficient at run time, but impractical if the output is huge (e.g., exponential increase for permutation);
  2. By using the correct algorithm (included here but not used) to generate the output at run time. This needs more calculation, is less efficient, but is more feasible when the output is large.
Right now the code can be submitted to homecoxoj at gmail.com. In the long run, it should be able to do this on Homecox.