poj 1256 Anagram

来源:互联网 发布:走遍中国中国古镇 知乎 编辑:程序博客网 时间:2024/06/05 14:15

按要求排序,然后调用next_permutation即可。

#include<iostream>#include<algorithm>#include<cstring>using namespace std;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 < (b + 32);}int main(){int num = 0;cin >> num;while(num--){char str[100];cin >> str;int length = strlen(str);sort(str, str+length, cmp);cout << str << endl;while(next_permutation(str, str + length, cmp)){cout << str << endl;}}return 0;}


0 0