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