0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtCoderでPythonコードテストを迅速に行うためのTips

Last updated at Posted at 2025-03-24

背景

AtCoderのコードテストの使い勝手が悪いので色々と探っている最中に見つけた方法を忘れないため記事にした。知っている人は普通に知っていると思う。

内容

ファイル構造

  • inputs : 入力例のファイルを格納するフォルダー
  • test-a1, test-a2 : 各入力例
  • code1.py, code2.py : 実行したい.pyファイル
.
├─ inputs/ 
│    ├─ test-a1
│    ├─ test-a2
│    └─ ...
├─ code1.py
├─ code2.py
└─ ...

1. code.py には通常通りに input() 関数を使って記述する。

n = int(input())
ans = sum([i for i in range(n)])
print(ans)

2. test-a1 にはコードの入力例などをコピペする。

6

3. ターミナルで下記コマンドを実行。

python3 code.py < inputs/test-a1
  • < は、Bashコマンドにおいてリダイレクトを行うための記号。具体的にはファイルの内容を標準入力としてコマンドに渡すため使用される。

Note:
a1, a2 などの入力ファイルは .txt を付けたほうが視認性が上がるが、入力例を次々変えて実行したい場合、拡張子が邪魔になるので今回は外すことにした。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?