您的位置:首页 > 其它

初级题:从考试成绩中划出及格线

2013-09-12 14:13 190 查看
初级题:从考试成绩中划出及格线
10个学生考完期末考试评卷完成后,A老师需要划出及格线,要求如下:
(1) 及格线是10的倍数;
(2) 保证至少有60%的学生及格;
(3) 如果所有的学生都高于60分,则及格线为60分

输入:输入10个整数,取值0~100
输出:输出及格线,10的倍数

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

const int PASS_SCORE = 60; //默认及格分数
const int SCORE_NUM = 10; //学生个数

int main()
{
vector<int> vecscore; //保存分数
int score;
cout<<"Please input "<<SCORE_NUM<<" integers in [0,100]."<<endl;
for(int i = 1;i <= SCORE_NUM; i++) //循环输入10个学生的分数值
{
cin>>score;
if(score >=0 && score <= 100) //判断输入值合法性
{
vecscore.push_back(score);
}
else
{
cout<<"please input integer between 0 and 100(including 0 and 100)."<<endl;
return 0;
}
}
sort(vecscore.begin(),vecscore.end(),less_equal<int>()); //对输入的10个分数值进行排序,从小到大
vector<int>::iterator it;
for(it = vecscore.begin();it != vecscore.end(); ++it) //输出排序后的分数值
{
cout<<*it<<" "<<endl;
}
if(vecscore[0] >= PASS_SCORE) //如果最小的分数值大于等于60,则及格分数为60
{
cout<<"the score for passing examination is 60"<<endl;
}
else
{
score = vecscore[4]-vecscore[4]%10; //为了保证60%的同学及格,至少需要保证6个同学的分数高于及格分数,从高到低以第6个同学的分数为参考,并保证及格分数为10的倍数
cout<<"the score for passing examination is:"<<score<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐