fork download
  1. #include <iostream>
  2. struct Elev {
  3. double h;
  4. char name[256];
  5. } a[100];
  6. int n, sol[100], used[100];
  7.  
  8. void display() {
  9. for(int i = 1; i <= n; ++i) printf("%s ", a[sol[i]].name);
  10. printf("\n");
  11. }
  12. void bk(int k) {
  13. if(k>n) display();
  14. else
  15. for(int i = 1; i <= n; ++i) {
  16. if(!used[i]) {
  17. if( (k == 1) || (k >1 && a[i].h >= a[ sol[k-1] ].h)) {
  18. sol[k] = i;
  19. used[i] = 1;
  20. bk(k+1);
  21. used[i] = 0; }
  22. }
  23. }
  24. }
  25. int main() {
  26. double x;
  27. char name[256];
  28. n = 3;
  29. std::cout<<"elevi=";
  30. std::cin>>n;
  31. for(int i = 1; i <= n; ++i) scanf("%s %lf", a[i].name, &a[i].h);
  32.  
  33. bk(1);
  34. }
  35.  
Success #stdin #stdout 0.01s 5280KB
stdin
4
maria 1.65
ion 1.60
mihai 1.78
ana 1.65
stdout
elevi=ion maria ana mihai 
ion ana maria mihai