a,b=(0..1).map{ gets }.map(&:chomp) puts b.gsub(/\d/, a.chars.each_with_index.map { [_2.to_s, _1] }.to_h)