码迷,mamicode.com
首页 > 其他好文 > 详细

[排列]poj1256

时间:2015-05-24 13:00:31      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:cmp   poj   

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

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

   }
}

[排列]poj1256

标签:cmp   poj   

原文地址:http://blog.csdn.net/u010582475/article/details/45950707

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!