Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- #require 'debug'
- require 'set'
- class FindString
- def initialize
- t=gets.to_i #Num of test cases
- @string_store=Array.new
- @query_store=Array.new
- #@hash_store=Hash.new
- @set_store=Set.new
- #Push all the Strings in Array
- 1.upto(t) do
- @string_store.push(gets)
- end
- query=gets.to_i
- #Query indexes Array
- 1.upto(query) do
- @query_store.push(gets.to_i)
- end
- calc_index #Calculate the index in final resulted array of union of substring
- end
- def calc_index
- =begin
- for string in @string_store do
- for c in 0...string.length
- index_to_sum=0
- while c+index_to_sum<string.length do
- substring=string[c..(c+index_to_sum)]
- unless @hash_store[substring]=='X'
- @hash_store[substring]='X'
- end
- index_to_sum+=1
- end
- end
- end
- =end
- for string in @string_store do
- for c in 0...string.length
- index_to_sum=0
- while c+index_to_sum<string.length do
- substring=string[c..(c+index_to_sum)]
- @set_store.add(substring)
- index_to_sum+=1
- end
- end
- end
- puts @set_store.size
- @set_store.each { |s| puts s }
- end
- end
- FindString.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement