Advertisement
dashohoxha

alien_language.rb

Apr 1st, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.45 KB | None | 0 0
  1. ### Solution of practice problem Alien Language
  2. ### https://code.google.com/codejam/contest/90101/dashboard#s=p0
  3.  
  4. L, D, N = gets.chomp.split.map { |s| s.to_i }
  5.  
  6. words = []
  7. for w in 1..D do
  8.   words << gets.chomp
  9. end
  10.  
  11. for t in 1..N do
  12.   pattern = gets.chomp
  13.  
  14.   pattern.gsub!('(', '[')
  15.   pattern.gsub!(')', ']')
  16.   regexp = Regexp.new(pattern)
  17.  
  18.   k = 0
  19.   for word in words do
  20.     k +=1 if word =~ regexp
  21.   end
  22.  
  23.   puts "Case ##{t}: #{k}"
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement