struct Item {
......
int calcWight();
}
bool comp(Item a, Item b)
{
return a.calcWeight() < b.calcWeight();
}
std::stable_sort(items.begin(), items.end(), comp);
struct Score
{
int score;
int idx;
}
int n = items.size();
for (int i = 0; i < n; ++i)
{
scores[i].score = items[i].calcWeight();
scores.idx = i;
}
bool comp(Score a, Score b)
{
return a.score < b.score;
}
stable_sort(scores, scores + n, comp);
......