fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_LENGTH = 100;
  5.  
  6. int main() {
  7. int n, planet[MAX_LENGTH + 1], people[MAX_LENGTH + 1];
  8. cin >> n;
  9. int x = 1;
  10. while (x <= n) {
  11. cin >> planet[x];
  12. cin >> people[x];
  13. //cout << planet[x] <<" " << people[x] <<" " << x << "\n";
  14. ++x;
  15. }
  16. while (x >= 1) {
  17. int index = 1;
  18. int highVal = 0, highPeo = 0;
  19. for (int i = 1; i <= n; ++i) {
  20. if (planet[i] > highVal && planet[i] != -1) {
  21. highVal = planet[i];
  22. highPeo = people[i];
  23. index = i;
  24. } else if (planet[i] == highVal && people[i] < highPeo ) {
  25. highVal = planet[i];
  26. highPeo = people[i];
  27. index = i;
  28. }
  29. }
  30. //cout << planet[index] <<" " << people[index] <<" " << index << "\n";
  31. cout << index <<" ";
  32. planet[index] = -1;
  33. people[index] = -1;
  34. --x;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5308KB
stdin
6
1 6
0 19
0 15
9 123456
1 99
6 123
stdout
4 6 1 5 1 1 1