3
4

More than 3 years have passed since last update.

pythonでAtcoderするためのVS Codeデバッグ環境作ってみた

Last updated at Posted at 2020-01-18

最近Atcoderデビューしたのですが、コードテストするときにあっちこっちタブ切り替えるのがちょっと面倒だったので…
VS CodeでF5デバッグできる環境を作ってみました。

環境


VS Code
バージョン: 1.41.1 (user setup)
コミット: 26076a4de974ead31f97692a0d32f90d735645c0
日付: 2019-12-18T14:58:56.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.17763

python
Python 3.7.3


作業用ディレクトリを作成し、その中に以下のファイルを作成、実行します。

make_directory.py
import os

for i in range(10):
    folder_name1 = "ABC{:x<3}".format(i)
    os.makedirs(folder_name1, exist_ok=True)

    for j in range(10):
        folder_name2 = folder_name1 + "/ABC{}{}x".format(i,j)
        os.makedirs(folder_name2, exist_ok=True)

        for k in range(10):
            folder_name3 = folder_name2 + "/ABC{}{}{}".format(i,j,k)
            os.makedirs(folder_name3, exist_ok=True)
            file_name = folder_name3 + "/ABC{}{}{}".format(i,j,k)

            with open(file_name + "A.py", mode='w') as f:
                pass
            with open(file_name + "B.py", mode='w') as f:
                pass
            with open(file_name + "C.py", mode='w') as f:
                pass
            with open(file_name + "D.py", mode='w') as f:
                pass
            with open(file_name + "E.py", mode='w') as f:
                pass
            with open(file_name + "F.py", mode='w') as f:
                pass
            with open(folder_name3 + "/input.txt", mode='w') as f:
                pass

そうすると、作業用ディレクトリの中にディレクトリとファイルが生成されます。

作成されるディレクトリ

100コンテスト単位のディレクトリ

10コンテスト単位のディレクトリ

1コンテスト単位のディレクトリ

作成されるファイル

ABC001A.py~ABC001F.py
input.txt

(1コンテスト単位のディレクトリの中)

launch.jsonも編集します。

atcoder_debugの部分が書き足されていて、各ディレクトリにあるinput.txtを引数で渡しています。

launch.json


{
    // IntelliSense を使用して利用可能な属性を学べます。
    // 既存の属性の説明をホバーして表示します。
    // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "atcoder Debugger",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args":[
                "<",
                "${fileDirname}/input.txt"
            ]
        },
    ]
}

あとは解いてる問題のpyファイルにコードを書いて、pyファイルのあるディレクトリのinput.txtに入力値をコピペして、F5キーを押せばデバッグできます。

3
4
2

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
3
4