#include<fstream>
#include<iostream>
using namespace std;
struct stu {
int id, chi, mat, eng, tot;
};
stu a[305];
int main() {
ifstream infile;//输入流
ofstream outfile;//输出流
int i=1;
int n;
infile.open("shuju.txt", ios::in);
if (!infile.is_open())
cout << "Open file failure" << endl;
infile >> n;
int s = n;
while (0!=n) // 若未到文件结束一直循环
{
infile >>a[i].chi >> a[i].mat>>a[i].eng;
a[i].id = i;
a[i].tot = a[i].chi + a[i].mat + a[i].eng;
i++;
n--;
}
infile.close();
for (int i = 1; i < n + 1; i++) {
for (int j = i + 1; j <= n; j++)
{
cout << "debug";
if (a[j].tot > a[i].tot ||
(a[j].tot == a[i].tot && a[j].chi > a[i].chi) ||
(a[j].tot == a[i].tot && a[j].chi == a[i].chi && a[j].id < a[i].id)) {
stu t = a[i]; a[i] = a[j]; a[j] = t;
}
}
};
outfile.open("jieguo.txt", ios::out);
if (!outfile.is_open())
cout << "Open file failure" << endl;
for (int i = 1; i<= s; i++)
outfile<< a[i].id << " " << a[i].tot << endl;
outfile.close();
return 0;
}