keep track of of vector pair indices upon sorting

Similar things have been asked before but I am having trouble applying the concept. I would like to to keep track of the indices of the pairs in my vector of pairs then, once sorted, std::cout the input order.

e.g.
cin >> 5 6 1 5 1 2 1 2 3 5
cout << 1 2 1 2 1 5 3 5 5 6
//and this is where I am having trouble
cout >> 3 4 2 5 1

I was thinking of converting to triples, where the last element is the index but that was causing headaches and errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>

using namespace std;

bool compare(const pair<int,int>&A, const pair<int,int>&B);

int main()
{
    vector<pair<int,int>> v;
    pair<int,int> tok;
    while(cin >> tok.first>>tok.second){v.push_back(tok);}
    
    sort(v.begin(),v.end(), compare);
    for(int i = (signed int)v.size()-1; i >= 0 ; i--)
    {
        cout << v.at(i).first << " ";
        cout << v.at(i).second << " ";
    }
    cout << endl;
    return 0;
}

bool compare(const pair<int,int>&A, const pair<int,int>&B)
{
    return A.first > B.first;
}
> I was thinking of converting to triples, where the last element is the index
yes, that's a good approach.


New topic wrote:
Put the code you need help with here.
your snip is irrelevant.
show the one were you try to store the index, the one with the errors.
Topic archived. No new replies allowed.