您的位置:首页 > 其它

poj 1256 Anagram

2015-07-03 02:41 411 查看
http://poj.org/problem?id=1256

题意是说求出一个字符串的全排列,按字典序

需要注意的是字典序和传统意义上的字典序不同

重新定义了,A<a<B<b的顺序

需要自己重写cmp函数。

next_permutation好神....直接求出全排列.....

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <map>

using namespace std;
bool cmp(char a,char b)
{
char x = tolower(a);
char y = tolower(b);
if (x==y)
{
return a<b;
}
else return x<y;
}
int n;
string st;

int main()
{
cin>>n;
while (n--)
{

cin>>st;
sort(st.begin(),st.end(),cmp);
do
{
cout<<st<<endl;
}while (next_permutation(st.begin(),st.end(),cmp));
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: