Codeforces Round #158 (Div. 2)

http://www.codeforces.com/contest/260

A,B問題だけ。

A. Adding Digits

def op(a, b)
  for i in 0 .. 9 do
    c = a * 10 + i
    return c if c % b == 0
  end
  
  -1
end

a, b, n = gets.chomp.split(" ").map{|n| n.to_i}

c = op(a, b)

if c == -1
  puts -1
else
  puts c.to_s + "0" * (a.to_s.length + n - c.to_s.length)
end

B. Ancient Prophesy

require 'date'

s = gets.chomp
hash = Hash.new {0}

(9 .. s.length).each do |idx|
  s2 = s[idx - 9 .. idx]
  match = s2.match(/(3[01]|[12][0-9]|0[1-9])-(1[0-2]|0[1-9])-(201[3-5])/)
  next if not match
  
  year, month, date = match[3].to_i, match[2].to_i, match[1].to_i  

  if Date.valid_date? year, month, date
    d = Date.new year, month, date
    hash[d] += 1
  end
end
ans = hash.max_by { |k, v| v }.first
puts ans.strftime "%d-%m-%Y"