POJ_1256_Anagram

POJ_1256_Anagram
题意:字符串排列,大写字母较小写字母对应小(A < b < C)
思路:先写一个比较函数在sort一下,再利用STL中next_permutation输出所有从小到大的排列。


#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>

#define debug(x) cout << "--------------> " << x << endl

using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-10;
const long long INF = 0x7fffffff;
const long long MOD = 1000000007;

bool cmp(const char &a, const char &b)
{
    if(a <= 'Z' && a >= 'A' && b <= 'Z' && b >= 'A')
        return a < b;
    if(a <= 'z' && a >= 'a' && b <= 'z' && b >= 'a')
        return a < b;
    if(a <= 'Z' && a >= 'A' && b <= 'z' && b >= 'a')
        return a + 32 <= b;
    if(a <= 'z' && a >= 'a' && b <= 'Z' && b >= 'A')
        return a - 32 < b;
}

int main()
{
    int n;
    scanf("%d", &n);
    while(n--)
    {
        char str[27];
         cin >> str;
         int len = strlen(str);
         sort(str, str+len, cmp);
         cout << str << endl;
         while(next_permutation(str, str+len, cmp))
         {
            cout << str << endl;
         }
    }
     return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值