Advertisement
Guest User

toph_anagram

a guest
Apr 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int fact(int x) //defining the function or function definition
  5. {
  6. int i, f=1;
  7. for(i=2; i<=x; i++)
  8. {
  9. f=f*i;
  10. }
  11. return f;
  12. }
  13. int main()
  14. {
  15. int t;
  16. scanf("%d", &t);
  17. string str;
  18. for(int cs=1;cs<=t; cs++)
  19. {
  20. cin >> str;
  21. int x = str.size();
  22. map <int, int> mp;
  23. for(int i=0; i<x; i++)
  24. {
  25. mp[str[i]]++;
  26. }
  27. int ans = 1;
  28. map <int, int>:: iterator it;
  29. for(it= mp.begin(); it!=mp.end(); it++)
  30. ans *= fact(it->second);
  31.  
  32. printf("Case %d: %d\n", cs, fact(x)/ans);
  33. mp.clear();
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement