[排列]poj1256

題意:
給出一個串,要求按照字典序輸出所有排列。

分析:
直接利用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 35
using 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));

   }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章