时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Li
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”
现给出一批考生的德才分数,请根据司马光的理论给出录取排名。
输入格式:
输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线L的考生也按总分排序,但排在第三类考生之后。
随后N行,每行给出一位考生的信息,包括:准考证号、德分、才分,其中准考证号为8位整数,德才分为区间[0, 100]内的整数。数字间以空格分隔。
输出格式:
输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。
输入样例:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
输出样例:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
struct student
{
int sno;
int descore;
int caiscore;
}stu;
bool Sortarr( student a1, student a2)
{
if (a1.caiscore + a1.descore != a2.caiscore + a2.descore)
{
return( a1.caiscore + a1.descore) > (a2.caiscore + a2.descore);//因为这里没有加两个括号导致我2个测试点一直超时,查找了一万遍才找到原因
}
else
{
if (a1.descore!=a2.descore)
{
return a1.descore > a2.descore;
}
else
{
return a1.sno < a2.sno;
}
}
}
int main()
{
int StudentNums, PassScore, GoodScore;
int count = 0;
cin >> StudentNums >> PassScore >> GoodScore;
vector<student> v1, v2, v3, v4;
for (int i = 0; i < StudentNums; i++)
{
cin >> stu.sno >> stu.descore >> stu.caiscore;
if (stu.caiscore >= PassScore&&stu.descore >= PassScore)
{
if (stu.caiscore >= GoodScore&&stu.descore >= GoodScore)
{
v1.push_back(stu);
}
else if (stu.caiscore < GoodScore&&stu.descore >= GoodScore)
{
v2.push_back(stu);
}
else if (stu.caiscore < GoodScore&&stu.descore < GoodScore&&stu.caiscore <= stu.descore)
{
v3.push_back(stu);
}
else
{
v4.push_back(stu);
}
count++;//及格人数
}
}
cout << count << endl;
sort(v1.begin(), v1.end(), Sortarr);//排序vector里的元素
sort(v2.begin(), v2.end(), Sortarr);
sort(v3.begin(), v3.end(), Sortarr);
sort(v4.begin(), v4.end(), Sortarr);
for (int i = 0; i<v1.size(); i++)
{
cout << v1[i].sno << " " << v1[i].descore << " " << v1[i].caiscore << endl;
}
for (int i = 0; i<v2.size(); i++)
{
cout << v2[i].sno << " " << v2[i].descore << " " << v2[i].caiscore << endl;
}
for (int i = 0; i<v3.size(); i++)
{
cout << v3[i].sno << " " << v3[i].descore << " " << v3[i].caiscore << endl;
}
for (int i = 0; i<v4.size(); i++)
{
cout << v4[i].sno << " " << v4[i].descore << " " << v4[i].caiscore << endl;
}
return 0;
}
重载法:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
struct student
{
int sno;
int descore;
int caiscore;
bool operator <(const student &A) const{
if (descore + caiscore != A.descore + A.caiscore)
return (descore + caiscore)>(A.descore + A.caiscore);
else if (descore != A.descore)
return descore>A.descore;
else return sno<A.sno;
}
}stu;
int main()
{
int StudentNums, PassScore, GoodScore;
int count = 0;
cin >> StudentNums >> PassScore >> GoodScore;
vector<student> v1, v2, v3, v4;
for (int i = 0; i < StudentNums; i++)
{
cin >> stu.sno >> stu.descore >> stu.caiscore;
if (stu.caiscore >= PassScore&&stu.descore >= PassScore)
{
if (stu.caiscore >= GoodScore&&stu.descore >= GoodScore)
{
v1.push_back(stu);
}
else if (stu.caiscore < GoodScore&&stu.descore >= GoodScore)
{
v2.push_back(stu);
}
else if (stu.caiscore < GoodScore&&stu.descore < GoodScore&&stu.caiscore <= stu.descore)
{
v3.push_back(stu);
}
else
{
v4.push_back(stu);
}
count++;//及格人数
}
}
cout << count << endl;
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
sort(v3.begin(), v3.end());
sort(v4.begin(), v4.end());
vector<student>::iterator it;
for (it = v1.begin(); it != v1.end(); it++)
{
cout << it->sno << " " << it->descore << " " << it->caiscore << endl;
}
for (it = v2.begin(); it != v2.end(); it++)
{
cout << it->sno << " " << it->descore << " " << it->caiscore << endl;
}
for (it = v3.begin(); it != v3.end(); it++)
{
cout << it->sno << " " << it->descore << " " << it->caiscore << endl;
}
for (it = v4.begin(); it != v4.end(); it++)
{
cout << it->sno << " " << it->descore << " " << it->caiscore << endl;
}
return 0;
}