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;
}