POJ 1256 Anagram 发表于 2016-10-15 | 分类于 STL | | 阅读次数 sort与next_permutation函数在字符串中的应用 题目链接POJ 1256 题目大意给你一个含有大小写英文字母的字符串,按照’A’<’a’<’B’<’b’<…<’Z’<’z’的方式排列,输出所有的排列。 AC代码1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <iostream>#include <algorithm>#include <functional>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;} 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏 支付宝打赏