poj 1256 全排列

第二次做全排列的题了,又有了不小的收获,c++中有专门做全排列的函数 

next_permutation();所以方便了不少;在STL库中;

 

 

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

bool cmp(char a,char b){
if(tolower(a) == tolower(b)) //tolwer()函数作用是将大写字母转变为小写字母
return a < b;
else
return tolower(a) < tolower(b);
}

int main()
{ int n;
string str;

cin>>n;
while(n--)
{
cin >> str;

sort(str.begin(), str.end(),cmp);
cout << str << endl;
while (next_permutation(str.begin(), str.end(),cmp))
{
cout << str << endl;
}
// str.clear();
}

}

posted on 2012-10-20 20:04  元点之始  阅读(278)  评论(0编辑  收藏  举报

导航