fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5.  
  6. using namespace __gnu_pbds;
  7.  
  8. typedef tree<pair<int,int>, null_type, std::less<pair<int,int>>, rb_tree_tag,
  9. tree_order_statistics_node_update> ordered_set;
  10. #define ll long long
  11. #define ld long double
  12. #define all(s) s.begin(),s.end()
  13. #define rall(s) s.rbegin(),s.rend()
  14.  
  15. const ll INF = 1e9;
  16. const ll mod = 1e9 + 7;
  17. vector<string>res;
  18. void rec(int idx , string s , string cur){
  19. if(idx == s.size()){
  20. string tmp = cur;
  21. reverse(all(tmp));
  22. if(tmp == cur){
  23. res.push_back(cur);
  24. }
  25. return ;
  26. }
  27. string tmp = cur;
  28. reverse(all(tmp));
  29. if(cur == tmp){
  30. res.push_back(cur);
  31. }
  32. rec(idx+1,s,cur+s[idx]);
  33. rec(idx+1,s,"");
  34. }
  35. void Bavly() {
  36. string s ;
  37. cin >> s;
  38. rec(0,s,"");
  39. sort(all(res));
  40. for(auto i : res){
  41. if(i.size())cout << i << "\n";
  42. }
  43. }
  44.  
  45. int main(){
  46. ios::sync_with_stdio(false);
  47. cin.tie(NULL);
  48. cout.tie(NULL);
  49. #ifndef ONLINE_JUDGE
  50. freopen("input.txt", "r", stdin);
  51. freopen("output.txt", "w", stdout);
  52. #endif
  53. ll t =1;
  54. //cin >> t;
  55. while(t--){
  56. Bavly();
  57. }
  58. }
Success #stdin #stdout 0s 5324KB
stdin
abba
stdout
a
a
a
a
a
abba
b
b
b
bb