Uva 195 Solution

#include<bits/stdc++.h>
using namespace std;

bool check(char a, char b)
{
    if(tolower(a) == tolower(b))
        return a<b;

    return tolower(a) < tolower(b);
}

int main()
{
    int n, i;
    while(cin >> n)
    {
        getchar();
        for(i=1; i<=n; i++)
        {
            string s;
            cin >> s;
            sort(s.begin(), s.end(), check);
            cout << s << endl;
            while(next_permutation(s.begin(), s.end(), check))
            {
                cout << s << endl;
            }
        }
    }
    return 0;
}

Comments