1839:【05NOIP提高组】谁拿了最多奖学金
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 12887 通过数: 6063
【题目描述】
某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同:
1)院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得;
2)五四奖学金,每人4000元,期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生均可获得;
3)成绩优秀奖,每人2000元,期末平均成绩高于90分(>90)的学生均可获得;
4)西部奖学金,每人1000元,期末平均成绩高于85分(>85)的西部省份学生均可获得;
5)班级贡献奖,每人850元,班级评议成绩高于80分(>80)的学生干部均可获得;
只要符合条件就可以得奖,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。例如姚林的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。
现在给出若干学生的相关数据,请计算哪些同学获得的奖金总数最高(假设总有同学能满足获得奖学金的条件)。
【输入】
第一行是一个整数N(1 <= N <= 100),表示学生的总数。接下来的N行每行是一位学生的数据,从左向右依次是姓名,期末平均成绩,班级评议成绩,是否是学生干部,是否是西部省份学生,以及发表的论文数。姓名是由大小写英文字母组成的长度不超过20的字符串(不含空格);期末平均成绩和班级评议成绩都是0到100之间的整数(包括0和100);是否是学生干部和是否是西部省份学生分别用一个字符表示,Y表示是,N表示不是;发表的论文数是0到10的整数(包括0和10)。每两个相邻数据项之间用一个空格分隔。
【输出】
三行,第一行是获得最多奖金的学生的姓名,第二行是这名学生获得的奖金总数。如果有两位或两位以上的学生获得的奖金最多,输出他们之中在输入文件中出现最早的学生的姓名。第三行是这N个学生获得的奖学金的总数。
思路:很久之前用类来做的,思路忘了,应该看代码就能看得懂(应该有更好的方法,这个代码太多了)。
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<string>
using std::string;
#include<iomanip>
using std::fixed;
using std::setprecision;
class student
{
public:
student()
{
this->m_name = " ";
this->m_score_study = 0;
this->m_score_class = 0;
this->m_classLeader = ' ';
this->m_whether_westStudent = ' ';
this->m_article = 0;
this->m_scholarship = 0;
}
void set(string name, int score_study, int score_class, char classLeader, char whether_westStudent, int article)
{
this->m_name = name;
this->m_score_study = score_study;
this->m_score_class = score_class;
this->m_classLeader = classLeader;
this->m_whether_westStudent = whether_westStudent;
this->m_article = article;
}
string m_name;
int m_score_study;
int m_score_class;
char m_classLeader;
char m_whether_westStudent;
int m_article;
int m_scholarship;
};
int main()
{
int n = 0;
cin >> n;
student a[100];
string name;
int score_study;
int score_class;
char classLeader;
char whether_westStudent;
int article;
for (int i = 0; i < n; ++i)
{
cin >> name >> score_study >> score_class >> classLeader >> whether_westStudent >> article;
a[i].set(name, score_study, score_class, classLeader, whether_westStudent, article);
}
for (int i = 0; i < n; ++i)
{
if (a[i].m_score_study > 80 && a[i].m_article >= 1)
{
a[i].m_scholarship += 8000;
}
if (a[i].m_score_study > 85 && a[i].m_score_class > 80)
{
a[i].m_scholarship += 4000;
}
if (a[i].m_score_study > 90)
{
a[i].m_scholarship += 2000;
}
if (a[i].m_score_study > 85 && a[i].m_whether_westStudent == 'Y')
{
a[i].m_scholarship += 1000;
}
if (a[i].m_score_class > 80 && a[i].m_classLeader == 'Y')
{
a[i].m_scholarship += 850;
}
}
int sumOfScholarship = 0;
for (int i = 0; i < n; ++i)
{
sumOfScholarship += a[i].m_scholarship;
}
string max_name=a[0].m_name ;
int max_scholsrship = a[0].m_scholarship ;
for (int i = 1; i < n; ++i)
{
if (max_scholsrship < a[i].m_scholarship)
{
max_scholsrship = a[i].m_scholarship;
max_name = a[i].m_name;
}
}
cout << max_name << endl;
cout << max_scholsrship << endl;
cout << sumOfScholarship;
}