Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.6 kB
18
Indexable
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, b) for(int i = 0; i < b; i++)
#define PER(i, b) for(int i = b - 1; i >= 0; i--)
#define fi first
#define se second
#ifdef JASPER2
#include "debug.h"
#else
#define debug(...) 166
#endif

using pii = pair < int, int >;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int N = 1e2 + 5;

string s;
int n;
vector <string> ans;

bool isPalin(string x) {
    string rx = x;
    reverse(x.begin(), x.end());
    return(rx == x && !x.empty());
}

void solve(int i, string str) {
    if (i == n + 1) {
        string check = "";
        for (auto x : ans) check += x;
        if (check.size() != s.size()) return;

        for (auto x : ans)
            cout << x << " ";
        cout << "\n";
        return;
    }

    // Tai vi tri i, ta co 2 cach di: 1. Neu xau hien tai la palin -> bat dau 1 xau moi 2. Tiep tuc xau hien tai
    // Bat dau xau moi
    if (isPalin(str)) {
        ans.push_back(str);
        string n_str;
        solve(i + 1, n_str + (char) (s[i]));
        ans.pop_back();
    }
    // Tiep tuc xau hien tai
    solve(i + 1, str + (char) (s[i]));
} 
void run_case() {
    cin >> s;
    n = s.size();
    solve(0, "");
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    #ifdef JASPER2
        freopen("in1", "r", stdin);
    #endif

    int Test = 1;
    //cin >> Test;
    for (int test = 1; test <= Test; test++){

        run_case();
    }
}