Created
October 26, 2010 12:05
-
-
Save dwiash/646788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # to run this script, type this line in your console: | |
| # | |
| # $ ruby alien_language.rb < input_file.txt > output_file.txt | |
| # | |
| # | |
| # this script tested with ruby 1.8.7 patchlevel 72 | |
| input_array = readlines | |
| var = input_array[0].split(" ") | |
| L = var[0].to_i | |
| D = var[1].to_i | |
| N = var[2].to_i | |
| dictionary = [] | |
| (1..D).each do | |
| |i| | |
| dictionary.push(input_array[i]) | |
| end | |
| test_case = [] | |
| (D+1..D+N).each do | |
| |i| | |
| test_case.push(input_array[i]) | |
| end | |
| num_case = 1 | |
| test_case.each do | |
| |line| | |
| counter = 0 | |
| line = line.gsub("(", "[") | |
| line = line.gsub(")", "]").strip | |
| dictionary.each do | |
| |item| | |
| item = item.strip | |
| eval('counter = counter+1 if "'+ item +'" =~ /^'+ line +'$/') | |
| end | |
| puts "Case ##{num_case}: #{counter}" | |
| num_case = num_case + 1 | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment