poj-1256 Anagram 全排列
2013-08-14 17:45
447 查看
题目来源:http://poj.org/problem?id=1256
题目大意是求字符串的全排列 要求按A<a<B<b<...<Z<z 的顺序输出
那就把给定的字符串先排序
然后通过STL的next_permutation函数生成全排列(C++)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
bool cmp(char a, char b)
{
int asc1, asc2;
asc1 = (a >= 'a' && a <= 'z') ? (a - 'a')*2 + 1 : (a - 'A')*2;
asc2 = (b >= 'a' && b <= 'z') ? (b - 'a')*2 + 1 : (b - 'A')*2;
return asc1 < asc2;
}
int main()
{
int total, len;
char str[13];
scanf("%d", &total);
while(total--)
{
scanf("%s", str);
len = strlen(str);
sort(str,str+len,cmp);
printf("%s\n", str);
while(next_permutation(str, str+len,cmp))
printf("%s\n", str);
}
}
题目大意是求字符串的全排列 要求按A<a<B<b<...<Z<z 的顺序输出
那就把给定的字符串先排序
然后通过STL的next_permutation函数生成全排列(C++)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
bool cmp(char a, char b)
{
int asc1, asc2;
asc1 = (a >= 'a' && a <= 'z') ? (a - 'a')*2 + 1 : (a - 'A')*2;
asc2 = (b >= 'a' && b <= 'z') ? (b - 'a')*2 + 1 : (b - 'A')*2;
return asc1 < asc2;
}
int main()
{
int total, len;
char str[13];
scanf("%d", &total);
while(total--)
{
scanf("%s", str);
len = strlen(str);
sort(str,str+len,cmp);
printf("%s\n", str);
while(next_permutation(str, str+len,cmp))
printf("%s\n", str);
}
}
相关文章推荐
- poj 1256 深搜全排列 Anagram
- POJ 1256 Anagram【生成有重集的全排列2.0】
- 不重复排列 POJ 1256 Anagram
- POJ 1256 Anagram
- POJ - 1256 Anagram
- POJ 1256:Anagram
- POJ 1256 Anagram
- POJ 1256:Anagram
- poj 1256 Anagram
- poj 1256 Anagram
- poj 1256 全排列
- poj 1256(Anagram)
- POJ_1256_Anagram
- (Relax ST1.7)POJ 1256 Anagram(求一个字符串在特殊规定下的全排列)
- poj 1256(Anagram + 求全排列算法)
- POJ 1256 Anagram 笔记
- POJ 1256 Anagram
- poj 1256 Anagram
- POJ 1256.Anagram(DFS和STL)
- POJ1256 Anagram