[排列]poj1256

来源:互联网 发布:php 读取json对象 编辑:程序博客网 时间:2024/05/22 06:24

题意:
给出一个串,要求按照字典序输出所有排列。

分析:
直接利用STL 里的next_permutation()就好,重新定义一个cmp函数,没有把cmp放进next_permutation(),我都WA哭了。。。

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <vector>#include <map>#include <queue>#include <algorithm>#define read freopen("q.in","r",stdin)#define LL long long#define maxn 35using namespace std;bool cmp(char x,char y){   if(tolower(x)!=tolower(y))return tolower(x)<tolower(y);   else return x<y;}int main(){    //read;    //cout<<'a'-'A'<<endl;   int t;   cin>>t;   while(t--)   {       char str[maxn];       cin>>str;       int len=strlen(str);       sort(str,str+len,cmp);       do       {          printf("%s\n",str);       }while(next_permutation(str,str+len,cmp));   }}
0 0
原创粉丝点击