AtCoder Regular Contest #002
http://arc002.contest.atcoder.jp/
A, B, C問題だけ。
A. うるう年
def is_leap_year(year) if year % 400 == 0 true elsif year % 100 != 0 and year % 4 == 0 true else false end end y = gets.chomp.to_i puts is_leap_year(y) ? "YES" : "NO"
B. 割り切れる日付
require 'date' def is_divisible(y, m, d) if (y.to_f / m.to_f / d.to_f) != (y / m / d).to_f false else true end end y, m, d = gets.chomp.split("/").map{|e| e.to_i} date = Date.new y, m, d while is_divisible(date.year, date.month, date.day) != true date += 1 end puts "%04d/%02d/%02d" % ([date.year, date.month, date.day])
C. コマンド入力
n = gets.chomp.to_i c = gets.chomp keys = ["A", "B", "X", "Y"].repeated_permutation(2) { |a, b| keys << a + b } values = keys.combination(2) { |a, b| values << c.gsub(/#{a}|#{b}/, "z").length } puts values.min