51NOD 1384

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <set>
using namespace std;

bool vis[10];
string ch;
int len;

void dfs(int k, string s)
{
    if(k == 0){
        cout<<s<<endl;
        return;
    }

    for(int i = 0; i < len; i++){
        if(!vis[i]){

            vis[i] = true;
            dfs(k-1, s+ch[i]);
            vis[i] = false;
            while(i < len && ch[i] == ch[i+1])
                i++;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    while(cin>>ch){
        memset(vis, 0, sizeof(vis));
        len = ch.length();
        sort(ch.begin(), ch.end());
        string temp;
        dfs(len, temp);
    }
    return 0;
}
posted @ 2017-07-26 21:54  />.<\  阅读(77)  评论(0编辑  收藏  举报