mootoh (owner)

Revisions

gist: 180895 Download_button fork
public
Public Clone URL: git://gist.github.com/180895.git
Embed All Files: show embed
AlienLanguage.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def solve(words, pattern)
   matched = 0
 
   regexp = Regexp.new pattern.gsub(/\(/, '[').gsub(/\)/, ']')
 
   words.each do |word|
      matched += 1 if regexp.match word
   end
 
   matched
end
 
L, D, N = ARGF.gets.split(/\s/).map {|x| x.to_i}
 
words = Array.new(D)
D.times do |i|
   words[i] = ARGF.gets.chomp
end
 
N.times do |i|
   puts "Case ##{i+1}: #{solve(words, ARGF.gets.chomp)}"
end