# 入力された値を受け取る A = gets.chomp S = gets.chomp S.length.times do |i| hoge = S[i] if !hoge.match(/\d/).nil? S[i] = A[hoge.to_i] end end puts S