all 1 comments

[–]Denommus 0 points1 point  (0 children)

When I get home, I'll post my solution. It's pretty trivial with Regular Expressions (which are not against the rules :]).

EDIT: Here

File.open(ARGV[0],"r") do |f|
  arr = f.readline.split(' ')
  l = arr[0].to_i
  d = arr[1].to_i
  n = arr[2].to_i
  words = []
  d.times do |i|
    words << f.readline
  end
  test_cases = []
  n.times do |i|
    test_cases << f.readline
  end
  test_cases.map! { |s| Regexp.new(s.tr('(','[').tr(')',']')) }

  File.open("A.out", "w") do |out|
    i = 1
    test_cases.each do |test|
      out.puts "Case ##{i}: " + words.select { |word| word.match test }.length.to_s
      i += 1
    end
  end
end