这是一道全排列的题目,原来经过修改,代码可以写得如此精炼!
/* Poj 1256, Wroter by Dream Chen, 2010/12/12*/
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
char str[20];
int length = 0;
inline bool cmp(char a, char b)
{
if (tolower(a) == tolower(b))
{
return a < b;
}
else
return tolower(a) < tolower(b);
}
int main(void)
{
memset((void*)str,0,sizeof(str));
int n = 0;
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
scanf("%s",str);
sort(str,str+strlen(str),cmp);
do
{
printf("%s/n",str);
} while (next_permutation(str,str+strlen(str),cmp));
}
return 0;
}