fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. std::vector<int> a{ 4, -5, 976, 776, 324, -987 };
  8. std::vector<int> b(a.size());
  9. std::iota(begin(b), end(b), 0);
  10.  
  11. std::sort(begin(b), end(b), [&](int i, int j) { return a[i] < a[j]; });
  12.  
  13. for (const auto& e : b) {
  14. std::cout << e << std::endl;
  15. }
  16.  
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
5
1
0
4
3
2