POJ1256-Anagram

http://poj.org/problem?id=1256

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
char str[20];
bool cmp(char a,char b)
{
    if(tolower(a)==tolower(b))  
       return a<b;
    return tolower(a)<tolower(b);
}
int main(void)
{
    int T;
    while(scanf("%d",&T)!=EOF)
    {
        while(T--)
        {
            scanf("%s",str);
            int n=strlen(str);
            sort(str,str+n,cmp);
            printf("%s\n",str);
            while(next_permutation(str,str+n,cmp))
               printf("%s\n",str);
        }
    }
    return 0;
}
posted @ 2012-10-08 19:59  Yogurt Shen  阅读(214)  评论(0编辑  收藏  举报