2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AtCoderのコーディング環境の設定

Last updated at Posted at 2022-01-25

AtCoderのコーディング環境を改善する

atcoder-cli, pypy3の追加を行う。

前回の環境

vscode, c/c++, python, docker, online judge toolsの環境構築
dockerfileの設定が誤っていました。
そこも改善していきたいです。

docker

dockerfile

「apt-get -y install --no-install-recommends」の後の記述を変更。
atcoder-cliの為に、nodejs、npmをインストールします。

dockerfile
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.134.0/containers/cpp/.devcontainer/base.Dockerfile
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
# C++, Python3, PyPy3の3つの環境想定
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends \
    python3-pip \
    pypy3 \
    nodejs \
    npm \
    && pip3 install online-judge-tools \
    && npm install -g atcoder-cli \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf ~/.cache/pip \
    && npm cache clean --force

devcontainer.json

「postCreateCommand」をコメントアウト。

devcontainer.json
    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "gcc -v",
    //"postCreateCommand": "pip3 install -r requirements.txt",

vscode

launch.json

デバッグ実行で使用するa.outのパスを変更。

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "<input.txt"
            ],
        },
        {
            "name": "C++: Current File",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/a.out",
            "args": [
                "<input.txt"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build Main"
        }
    ]
}

tasks.json

online judge toolsで使用するa.outの出力先を変更。

tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Main",
            "type": "shell",
            "command": "g++",
            "args": [
                "-std=c++17",
                "-g",
                "${relativeFile}",
                "-o",
                "${fileDirname}/a.out"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

atcoder cli

atcoder-cli チュートリアル
templateの設定。
まず隠しフォルダへ移動。
cppフォルダ、pyフォルダを作成。

cmd
cd `acc config-dir`
mkdir cpp
mkdir py

各フォルダにtemplate.jsonとtemplateのファイルを配置。

template.json
{
  "task":{
    "program": ["main.cpp"],
    "submit": "main.cpp"
  }
}
template.json
{
  "task":{
    "program": ["main.py"],
    "submit": "main.py"
  }
}

コマンドで確認。

cmd
 acc templates

cmd

cppとpyの使い分けは、

cmd
 acc  add --templates cpp
 acc  add --templates py

サンプルケースの実行cmdは、下記となります。
小文字でないと動作しないです。

cmd
#C++
oj t -c -d ./tests/
#python3
oj t -c "python3 ./main.py" -d ./tests/
#pypy3
oj t -c "pypy3 ./main.py" -d ./tests/

まとめ

前回のバグ修正。
online judge toolsとatcoder-cliの連携が終わりました。

プロジェクトはgithubにあります

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?