Atcoder用ディレクトリ作成スクリプト(C++/CMake)

を作成した。

#!/usr/bin/env ruby
# coding: utf-8

### Describe
# Put this script file in a directry you like.
# And command "ruby <this script file name>".
# Then input a contest name(ex: ABC042).
# mkdir ./ABC042
# touch ./ABC042/a_question.cpp
# touch ./ABC042/b_question.cpp
# touch ./ABC042/c_question.cpp
# touch ./ABC042/d_question.cpp
# touch ./ABC042/CMakeLists.txt

CPP_TEMPLATE =
'
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {

}
'

def mk_question_file(file_path)
  File.open(file_path, "w") do |file|
    file.write(CPP_TEMPLATE)
  end
end


puts "Input contest name. (ex: ABC042)\n"
input = STDIN.gets
contest_dir = input.chop

# カレントにコンテスト名のディレクトリを作成
begin
  Dir::mkdir(contest_dir)
rescue
  msg = "Error: ./#{contest_dir} dir already exits."
  puts msg
end

# コンテストディレクトリ直下に設問ごとのcppファイルを作成
exes = []
for x in ('a'..'d') do
  q_name = "#{x}_question"
  q_path = q_name + ".cpp"
  exes.push("add_executable (#{q_name} #{q_path})")
  file_path = "./#{contest_dir}/#{q_path}"
  mk_question_file(file_path)
end

# コンテストディレクト直下にCMakeLists.txtを作成
cmake_template = ["cmake_minimum_required (VERSION 3.1)",
                  "set (CMAKE_CXX_STANDARD 14)",
                  'set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-long-long -pedantic")',
                  "project (atcoder)",
                  ]
cmake_template.concat(exes)
cmake_file_path = "./#{contest_dir}/CMakeLists.txt"
File.open(cmake_file_path, "w") do |file|
  file.write cmake_template.join("\n\n")
end

puts "Info: Make ./#{contest_dir} dir have done."
puts "Info: Command \"cmake .\" in ./#{contest_dir}."

作成されるC++の雛形やC++のバージョンなど、気に入らない部分があれば適宜修正してくださいや。つーかこのRubyスクリプトを見たら、おれのカスみたいな英語力が丸裸だな。まあいいか。通じりゃええねん。

凋叶棕の『娶』をヘビロテしながらAtcoderの過去問を解いている。ドストレートに病んでる作品でいいっすね。サンプル公開時からやばい匂いプンプンだった「蛙姫」と、ノーマークだった「meaning of life」が特にお気に入り。