[2016-01-19][POJ][1256]
[2016-01-19][POJ][1256]
- 时间:2016-01-19 13:41:17 星期二
- 题目编号:POJ 1256
- 题目大意:给出一个word,求word组成字母的全排列,并输出
- 要求 输出顺序按字母顺序
- 字母顺序为 'A'<'a'<'B'<'b'<...<'Z'<'z'
- 方法:
- 通过上面的字母顺序构造一个cmp函数
- 先对原来的word进行重新排序
- 然后 用 next_permutation 进行生成后续排列,边生成边输出即可
- 解题过程遇到问题:
- next_permutation() 有第三个参数 ,cmp,可以根据cmp来生成.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cctype>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;bool cmp(char ch1,char ch2){ if( tolower(ch1) < tolower(ch2)) return 1; else if( tolower(ch1) == tolower(ch2) && ch1 < ch2 ) return 1; return 0;}int main(){ char str[20]; int t; cin>>t; while(t--){ cin>>str; vector<string> vec; int len = strlen(str); sort(str,str + len,cmp); do { cout<<str<<endl; }while( next_permutation( str,str + len,cmp)); } return 0;} |
浙公网安备 33010602011771号