fork download
  1. #include<iostream>
  2. using namespace std;
  3. int fact(int f)
  4. {
  5. if (f == 0) return 1;
  6. if (f <= 2) return f;
  7. return (f * fact(f - 1));
  8. }
  9. void solve(string s,int n)
  10. {
  11. int ans = 1;
  12. int arr[26] = {0};
  13. int len = n - 1;
  14. for (int i = 0; i < n; i++) {
  15. s[i] = toupper(s[i]);
  16. arr[s[i] - 'A']++;
  17. }
  18. for(int i = 0; i < n; i++) {
  19. int temp = 0;
  20. int x = 1;
  21. char c = s[i];
  22.  
  23. for(int j = 0; j < c - 'A'; j++) temp += arr[j];
  24. for (int j = 0; j < 26; j++) x = (x * fact(arr[j]));
  25. arr[c - 'A']--;
  26. ans = ans + (temp * ((fact(len)) / x));
  27. len--;
  28. }
  29. cout << ans;
  30. }
  31. int main()
  32. {
  33. int i,n;
  34. string s;
  35. cin>>s;
  36. n=s.size();
  37. solve(s,n);
  38. return 0;
  39. }
Success #stdin #stdout 0s 5292KB
stdin
KURWA
stdout
40