//2010-03 文件操作
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;
const int N = 10010;
struct stuinfo {
string name;
int id;
int eng;
int math;
int cs;
int tol;
}stu[N];
bool cmp(stuinfo a, stuinfo b)
{
if (a.tol == b.tol)
return a.id < b.id; //总分相同,id学号小的排在前
else
return a.tol > b.tol;
}
int main()
{
fstream file;
file.open("student.txt");
string line;
getline(file, line);
int i = 0;
while (getline(file,line))
{
istringstream ss(line);
ss >> stu[i].name >> stu[i].id >> stu[i].eng >> stu[i].math >> stu[i].cs;
i++;
stu[i].tol = stu[i].eng + stu[i].math + stu[i].cs;
}
sort(stu, stu + i, cmp);
for (int j = 0; j < i; j++)
cout << stu[i].name << ' ' << stu[i].id << ' ' << stu[i].tol << ' ' << stu[i].eng << ' ' << stu[i].math << ' ' << stu[i].cs << endl;
file.close();
return 0;
}
hdu 笔试2010-03
最新推荐文章于 2024-07-25 12:39:48 发布