首页 > 其他 > 详细

next_permutation,POJ(1256)

时间:2016-03-21 23:04:07      阅读:263      评论:0      收藏:0      [点我收藏+]

题目链接:http://poj.org/problem?id=1256

解题报告:

1、sort函数是按照ASC11码排序,而这里是按照 ‘A‘<‘a‘<‘B‘<‘b‘<...<‘Z‘<‘z‘排序。

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;


bool cmp(char a,char b)
{
    char m=tolower(a);
    char n=tolower(b);
    if(m==n)
        return a<b;
    else return m<n;
}


int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end(),cmp);
        do
        {
            cout<<s<<endl;
        }while(next_permutation(s.begin(),s.end(),cmp));
    }
    return 0;
}

 

next_permutation,POJ(1256)

原文:http://www.cnblogs.com/TreeDream/p/5304153.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!