本文主要是介绍九度考研真题 浙大 2011-2浙大1002:Grading,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目1002:Grading#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
double P,T,G1,G2,G3,Gj;
double num;
while(cin>>P)
{
cin>>T>>G1>>G2>>G3>>Gj;
if(fabs(G1-G2)<=T){
num=(G1+G2)/2.0;
}
else if(fabs(G1-G3)<=T&&fabs(G2-G3)>T||fabs(G3-G2)<=T&&fabs(G1-G3)>T){
if(G1<G2) num=(G1+G3)/2.0;
else num=(G2+G3)/2.0;
}
else if(fabs(G1-G3)<=T&&fabs(G3-G2)<=T){
if(G1<G2){
if(G2<G3) num=G3;
else num=G2;
}
else {
if(G1<G3) num=G3;
else num=G1;
}
}
else{
num=Gj;
}
printf("%.1f\n",num);
} //20 4 12 18 17 12 20 4 8 13 20 14
}
#include<stdio.h>
#include<math.h>
int main()
{
int P,T,G1,G2,G3,GJ,a,b,c;
float grade;
while(scanf("%d %d %d %d %d %d",&P,&T,&G1,&G2,&G3,&GJ)!=EOF)
{
a=fabs(G1-G2),b=fabs(G1-G3),c=fabs(G2-G3);//求绝对值
if(a<=T)
grade=(float)(G1+G2)/2;
else
{
if(b<=T&&c<=T)//求最大值
{
if(G1<G2)
G1=G2;
if(G1<G3)
G1=G3;
grade=(float)G1;
}
if(b>T&&c>T)
grade=(float)GJ;
if(b<=T)
grade=(float)(G1+G3)/2;
if(c<=T)
grade=(float)(G2+G3)/2;
}
printf("%.1f\n",grade);
}
return 0;
}
这篇关于九度考研真题 浙大 2011-2浙大1002:Grading的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!