🎁 Get the FREE AI Skills Starter Guide β€” Subscribe β†’
BytesAgainBytesAgain
πŸ¦€ ClawHub

NCCU OJ

by @andyjjrt

Solve competitive programming problems on NCCUOJ (https://nccuoj.ebg.tw). Use when: solving OJ problems, reading problem statements, writing solutions in C/C...

Versionv1.0.2
Downloads514
TERMINAL
clawhub install nccuoj

πŸ“– About This Skill


name: nccuoj description: "Solve competitive programming problems on NCCUOJ (https://nccuoj.ebg.tw). Use when: solving OJ problems, reading problem statements, writing solutions in C/C++/Python, submitting code, checking submission results." argument-hint: "Problem ID or URL (e.g. '1001' or 'https://nccuoj.ebg.tw/problem/1001')"

NCCUOJ Problem Solving

Solve competitive programming problems on NCCUOJ, a QDU-based Online Judge for NCCU CS.

When to Use

  • Read a problem statement from NCCUOJ
  • Write a solution for a specific problem
  • Submit code and check results
  • Debug a wrong answer or time limit exceeded
  • Solve contest problems
  • Directory Structure

    All generated files are organized under .nccuoj/ at the workspace root:

    .nccuoj/
    β”œβ”€β”€ cookies.txt                                  # Session cookies (auto-managed)
    └── solution/
        β”œβ”€β”€ public//                      # Public problem solutions
        β”‚   β”œβ”€β”€ problem.md                            # Problem statement
        β”‚   └── solution.cpp / solution.py / ...      # Solution code
        └── contest///        # Contest problem solutions
            β”œβ”€β”€ problem.md
            └── solution.cpp / solution.py / ...
    

    When writing solution code, always place files in the correct directory. The scripts' --save flag and get_solution_dir() helper handle directory creation automatically.

    CSRF Token (Important)

    All NCCUOJ API requests require a CSRF token. The provided scripts handle this automatically (via GET /api/profile on init). If making manual requests, see ./references/api.md for details.

    Scripts

    Use these scripts to interact with NCCUOJ. They handle CSRF tokens and session management automatically.

    | Script | Purpose | |--------|--------| | get_problem.py | Fetch problem statement as Markdown (supports --username/--password, --contest, --raw) | | submit.py | Submit code (requires --username / --password CLI args) | | check_result.py | Check submission result, with optional --poll |

    All scripts use only Python stdlib (no pip install needed).

    Scripts are located in this skill's ./scripts/ directory. In the examples below, $SCRIPTS refers to the absolute path of that directory. Resolve it relative to this SKILL.md file before running commands.

    Mode A: Public Problem Solving

    1. Fetch the Problem

    Run get_problem.py to fetch the problem. If the problem requires login (e.g. returns "Please login first"), ask the user for their credentials and pass --username/--password.

    # Public (no login)
    python $SCRIPTS/get_problem.py 

    With login

    python $SCRIPTS/get_problem.py --username --password

    Or if given a URL like https://nccuoj.ebg.tw/problem/1001, extract 1001 and pass it as the argument.

    The output is formatted Markdown containing: title, metadata (internal ID, difficulty, time/memory limit, tags), description, input/output format, sample test cases, hint, allowed languages, and statistics. All URL-encoded HTML fields are automatically decoded and converted to Markdown.

    Use --raw to get the original JSON instead.

    2. Analyze the Problem

  • Identify input/output format from input_description and output_description
  • Study sample cases from samples
  • Determine constraints (time/memory limits)
  • Identify the algorithm or data structure needed
  • 3. Write the Solution

    Write the solution file in the correct directory:

  • Public: .nccuoj/solution/public//solution.cpp (or .py, .java, etc.)
  • Contest: .nccuoj/solution/contest///solution.cpp
  • The supported languages are:

    | Language | API Name | Notes | |------------|---------------|---------------| | C | C | GCC, C17 | | C++ | C++ | GCC, C++20 | | Python | Python3 | Python 3.12 | | Java | Java | Temurin 21 | | Go | Golang | Go 1.22 | | JavaScript | JavaScript | Node.js 20 |

    Default to C++ unless the user specifies otherwise.

    #### C/C++ Template

    #include 
    using namespace std;

    int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // solution return 0; }

    #### Python Template

    import sys
    input = sys.stdin.readline

    def solve(): # solution pass

    solve()

    4. Test Locally

    Before submitting, verify the solution against the sample cases. Run the code with each sample input and compare to expected output.

    5. Submit (Optional)

    Before submitting, if the user has not provided their NCCUOJ username and password, ask them for it. Then pass the credentials directly as CLI arguments.

    # Submit (problem_id is the internal numeric ID from the problem JSON's "id" field)
    python $SCRIPTS/submit.py  "C++" .nccuoj/solution/public//solution.cpp --username  --password 

    Check result (with --poll to wait for judging)

    python $SCRIPTS/check_result.py --username --password --poll

    Result codes: -2 (Compile Error), -1 (Wrong Answer), 0 (Accepted), 1 (Time Limit Exceeded), 2 (Memory Limit Exceeded), 3 (Runtime Error), 4 (System Error), 6 (Pending), 7 (Judging), 8 (Partial Accepted).

    6. Debug if Needed

    If the submission is not Accepted:

  • Wrong Answer: Re-examine edge cases, off-by-one errors, output format
  • Time Limit Exceeded: Optimize algorithm complexity, reduce I/O overhead
  • Runtime Error: Check array bounds, division by zero, stack overflow
  • Compile Error: Check the error info in submission response
  • Memory Limit Exceeded: Reduce data structure size, avoid unnecessary copies
  • Mode B: Contest Problem Solving

    Contest mode mirrors public mode but all API calls require the contest_id parameter.

    1. Fetch Contest Problem

    Run get_problem.py with --contest. Contest problems always require login.

    python $SCRIPTS/get_problem.py  --contest  --username  --password 
    

    The response format is the same as public problems.

    2–4. Analyze, Write, Test

    Same as Mode A steps 2–4.

    5. Submit to Contest

    Before submitting, if the user has not provided their NCCUOJ username and password, ask them for it.

    python $SCRIPTS/submit.py  "C++" .nccuoj/solution/contest///solution.cpp --username  --password  --contest 

    Check result

    python $SCRIPTS/check_result.py --username --password --poll

    7. Debug if Needed

    Same as Mode A step 6. Note: contest submissions cannot be shared while the contest is underway.

    API Reference

    See ./references/api.md for full API endpoint documentation.

    ⚑ When to Use

    TriggerAction
    - Write a solution for a specific problem
    - Submit code and check results
    - Debug a wrong answer or time limit exceeded
    - Solve contest problems