- #include<iostream>
- using namespace std;
- #include<stack>
- #define N 27
- #define M 3
- stack<int> a ;
- void f(int j);
- char p[N]="abcdefghijklmnopqrstuvwxyz";
- void main()
- {
- f(1);
- cout<<endl ;
- }
- int count=0;
- void f(int j)
- {
- for(int c=1;c<=N-1;c++)
- {
- if( a.empty() || (a.top()<c&&c<=N-M+j) )
- {
- a.push(c);
- if(a.size()==M)
- {
- cout<<endl<<count++<<" : ";
- stack<int > b;
- while(!a.empty())
- {
- b.push(a.top());
- a.pop();
- }
- while(!b.empty())
- {
- cout<<p[b.top()-1];
- a.push(b.top());
- b.pop();
- }
- }
- f(j+1);
- a.pop();
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/101220137923.html
来源: http://www.codesnippet.cn/detail/101220137923.html