Advertisement
Guest User

Untitled

a guest
Jan 5th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.32 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. #require 'debug'
  4. require 'set'
  5.  
  6. class FindString
  7.  
  8.   def initialize
  9.     t=gets.to_i #Num of test cases
  10.     @string_store=Array.new
  11.     @query_store=Array.new
  12.     #@hash_store=Hash.new
  13.     @set_store=Set.new
  14.  
  15.     #Push all the Strings in Array
  16.     1.upto(t) do
  17.       @string_store.push(gets)
  18.     end
  19.  
  20.     query=gets.to_i
  21.     #Query indexes Array
  22.     1.upto(query) do
  23.       @query_store.push(gets.to_i)
  24.     end
  25.  
  26.     calc_index #Calculate the index in final resulted array of union of substring
  27.   end
  28.  
  29.   def calc_index    
  30.  
  31. =begin
  32.     for string in @string_store do
  33.       for c in 0...string.length
  34.         index_to_sum=0
  35.         while c+index_to_sum<string.length do
  36.           substring=string[c..(c+index_to_sum)]        
  37.           unless @hash_store[substring]=='X'
  38.             @hash_store[substring]='X'
  39.           end
  40.           index_to_sum+=1
  41.         end
  42.       end
  43.     end
  44. =end  
  45.    
  46.     for string in @string_store do
  47.       for c in 0...string.length
  48.         index_to_sum=0
  49.         while c+index_to_sum<string.length do
  50.           substring=string[c..(c+index_to_sum)]        
  51.           @set_store.add(substring)
  52.           index_to_sum+=1
  53.         end
  54.       end
  55.     end
  56.    
  57.     puts @set_store.size
  58.     @set_store.each { |s| puts s }
  59.   end  
  60. end
  61.  
  62. FindString.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement