fork(32) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. vector<int> data = {5, 16, 4, 7};
  9. vector<int> index(data.size(), 0);
  10. for (int i = 0 ; i != index.size() ; i++) {
  11. index[i] = i;
  12. }
  13. sort(index.begin(), index.end(),
  14. [&](const int& a, const int& b) {
  15. return (data[a] < data[b]);
  16. }
  17. );
  18. for (int i = 0 ; i != index.size() ; i++) {
  19. cout << index[i] << endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
2
0
3
1