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. if s.include? 'j' or s.include? 'J' or s.include? 'u' or s.include? 'U' or s.include? 'w' or s.include? 'W'
  16. puts "0"
  17. else
  18.  
  19. m = n
  20. n = s.length
  21. count = []
  22. i = 0
  23. while s[i]!=nil
  24. count << s.count(s[i])
  25.  
  26. s = s.gsub(s[i],"")
  27.  
  28. end
  29. n = count.length
  30. deno = 1
  31. (0..n-1).each{ |i|
  32. deno = deno * fact(count[i])
  33.  
  34.  
  35. }
  36.  
  37. print "%d\n" %"#{(fact(m)/deno)%mod}"
  38.  
  39. end
  40. t= t - 1
  41. end
Runtime error #stdin #stdout 0s 4760KB
stdin
4
ab
aa
aA
AAbaz
stdout
Standard output is empty