BUCTOJ1073

#include "iostream"
#include "algorithm"
using namespace std;
const int N = 7;
struct Time
{
    int a;
    int b;
    int c;
    int d;
};

bool cmp(const Time &A,const Time &B)
{
    if(A.c > B.c)
        return 1;
    if(A.c == B.c)
        return A.d < B.d;
    else
        return 0;

}


int main()
{
    Time time[N];
    int i;
    for( i=0;i<7;i++)
    {
        cin >> time[i].a >>time[i].b;
        time[i].c = time[i].a + time[i].b;
        time[i].d = i;
    }
    sort(time,time+7,cmp);

    if(time[0].c > 8)
        cout << time[0].d+1;
    else
        cout << "0";




    return 0;

}

第一:如何在排序的时候保留原先的下标

第二:如何在排序时增加当相等时的判断条件

原文地址:https://www.cnblogs.com/cunyusup/p/7696680.html