回溯法

#include <iostream>
#include <string>
using namespace std;

const int N = 10;

int n;
char path[N];
string str;
bool vis[N];

void dfs(int u)
{
    if (u == n)
    {
        for (int i = 0 ; i < n; ++i)
            cout << path[i];
        cout << endl;
        return;
    }
    for (int i = 0; i < n; ++i)
    {
        if (!vis[i])
        {
            vis[i] = true;
            path[u] = str[i];
            dfs(u + 1);
            vis[i] = false;
        }
    }
}

int main()
{
    cin >> str;
    n = str.size();
    dfs(0);
    return 0;
}