fork download
  1. def choose(m)
  2. self.factorial / (m.factorial * (self - m).factorial)
  3. end
  4. def fact (n)
  5. if n < 2
  6. return 1
  7. end
  8. (2..n).inject(1) { |f, n| f * n }
  9. end
  10. mod = 10**9 + 7
  11. t = gets.to_i
  12. while t > 0
  13.  
  14. s = gets.chomp
  15.  
  16. n = s.length
  17. m = n
  18.  
  19. count = []
  20. i = 0
  21. while s[i]!=nil
  22. count << s.count(s[i])
  23.  
  24. s = s.gsub(s[i],"")
  25.  
  26. end
  27. n = count.length
  28. deno = 1
  29. (0..n-1).each{ |i|
  30. deno = deno * fact(count[i])
  31.  
  32.  
  33. }
  34.  
  35. print "%d\n" %"#{(fact(m)/deno)%mod}"
  36.  
  37.  
  38. t= t - 1
  39. end
Success #stdin #stdout 0s 4760KB
stdin
4
ab
aa
aA
AAbaz
stdout
2
1
2
60