fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #define filein "partitiimultime.in"
  4. #define fileout "partitiimultime.out"
  5.  
  6. using namespace std;
  7.  
  8. int n, stack[100];
  9. ifstream fin(filein);
  10. ofstream fout(fileout);
  11.  
  12. int maxim(int level) {
  13. int max;
  14. max = 0;
  15. for(int i = 1; i < level; ++i) {
  16. if(stack[i] > max) max = stack[i];
  17. }
  18. return max;
  19. }
  20.  
  21. void display_partition() {
  22. int max = maxim(n+1);
  23. for (size_t i = 1; i <= max; i++) {
  24. for(int j = 1; j <= n; ++j) {
  25. if(stack[j] == i) cout<<j<<"";
  26. }
  27. cout<<"*";
  28. }
  29. cout<<endl;
  30. }
  31.  
  32. void solve(int level) {
  33. for(int i = 1; i <= maxim(level)+1; ++i) {
  34. stack[level] = i;
  35. if(level == n) {
  36. display_partition();
  37. } else solve(level+1);
  38. }
  39. }
  40.  
  41. int main(int argc, char const *argv[]) {
  42. cin>>n;
  43. stack[1] = 1;
  44. solve(2);
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.01s 5532KB
stdin
5
stdout
12345*
1234*5*
1235*4*
123*45*
123*4*5*
1245*3*
124*35*
124*3*5*
125*34*
12*345*
12*34*5*
125*3*4*
12*35*4*
12*3*45*
12*3*4*5*
1345*2*
134*25*
134*2*5*
135*24*
13*245*
13*24*5*
135*2*4*
13*25*4*
13*2*45*
13*2*4*5*
145*23*
14*235*
14*23*5*
15*234*
1*2345*
1*234*5*
15*23*4*
1*235*4*
1*23*45*
1*23*4*5*
145*2*3*
14*25*3*
14*2*35*
14*2*3*5*
15*24*3*
1*245*3*
1*24*35*
1*24*3*5*
15*2*34*
1*25*34*
1*2*345*
1*2*34*5*
15*2*3*4*
1*25*3*4*
1*2*35*4*
1*2*3*45*
1*2*3*4*5*