fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int scatterPalindrom(string s)
  6. {
  7. int n = s.size();
  8. int ans = 0;
  9. vector<int>A(n+1,0);
  10.  
  11. for(int i=1;i<=n;i++)
  12. {
  13. A[i] = A[i-1] ^ (1<<(s[i-1]-'a'));
  14. }
  15. int x;
  16. unordered_set<string>st;
  17. for(int i=1;i<=n;i++)
  18. {
  19. for(int j=i;j<=n;j++)
  20. {
  21. x = A[j]^A[i-1];
  22. if((x &(x-1) )==0)
  23. {
  24. if(st.count(s.substr(i-1,j-i+1))==0)
  25. {
  26. cout<<s.substr(i-1,j-i+1)<<endl;
  27. st.insert(s.substr(i-1,j-i+1));
  28. ans++;
  29. }
  30.  
  31.  
  32. }
  33. }
  34. }
  35. return ans;
  36. }
  37. int main()
  38. {
  39. string s;
  40. cin>>s;
  41. cout<<scatterPalindrom(s)<<endl;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5348KB
stdin
abc
stdout
a
b
c
3