language: Ruby (ruby-1.9.2)
date: 110 days 6 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
def choose(m)
    self.factorial / (m.factorial * (self - m).factorial)
  end
  def fact (n)
        if n <  2
        return 1 
        end
    (2..n).inject(1) { |f, n| f * n }
  end
mod = 10**9 + 7 
t = gets.to_i
while t > 0 
 
s = gets.chomp
n = s.length
m = n
count = []
i = 0
while i < n
count << s.count(s[i])
 n = n - s.count(s[i])
s = s.gsub(s[i],"")
i = i + 1
end
n = count.length
deno = 1
(0..n-1).each{ |i|
deno = deno * fact(count[i])
 
}
print "#{(fact(m)/deno)%mod}\n"
t= t - 1
end