0
1

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 3 years have passed since last update.

AtCoder用にディレクトリとA~ F問題のPythonファイルを作成した

Last updated at Posted at 2021-06-01

前置き

競プロにハマってしまいatcoderの過去の問題を全部解いてみたくなったので、まずは環境作りということでPythonさんに一括でファイルを作ってもらうことにしました

本題

コード

MakeFile.py
import os

def mkdir(*arg):
    diff = ["A","B","C","D","E","F"]
    if len(arg) == 1:
        try:
            os.mkdir(f"ABC{arg[0]}")
            for current_diff in diff:
                with open(f"ABC{arg[0]}/{current_diff}.py","w") as f:
                    f.write(f"# ABC{arg[0]}-{current_diff}\n")
        except:
            print(f"「ABC{arg[0]}」はもうあるよ")
    elif len(arg) == 2 :
        for i in range(arg[0], arg[1] +1):
            try:
                os.mkdir(f"ABC{i}")
                for current_diff in diff:
                    with open(f"ABC{i}/{current_diff}.py","w") as f:
                        f.write(f"# ABC{i}-{current_diff}\n")
            except:
                print(f"「ABC{i}」はもうあるから飛ばすね")
    else:
        print("引数多かったりしない?")

    print("終わったよ")

これでABC1 ~ ABC203までのディレクトリとA ~ F問題までのpythonファイルを作成してくれます
(D ~ F問題は僕は解くことがなさそうなので今のところ不要ですが(苦笑い) )

引数を下記のように指定することでで作成するファイルを一個から複数まで選べます(可変長引数を初めて使ってみた)

# ABC203だけ作成
mkdir(203)
# ABC1 ~ ABC202まで作成
mkdir(1,202)

例外処理で既に存在するディレクトリはスルーするようにしてあります

最後に

atcoderとても楽しいです、数学の勉強も頑張るぞー。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?