题目1002:Grading

来源:互联网 发布:世界政治格局 知乎 编辑:程序博客网 时间:2024/06/02 13:58
#include<iostream>
#include<cmath>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int main()
{
int P ,T ,G1,G2,G3,GJ;
float score ;
while(cin>>P>>T>>G1>>G2>>G3>>GJ)
{

if(abs(G1 - G2)<=T)
{
score=float(G1+G2)/2;
}
else 
{
int tem_g3g1 = G3 - G1;
int tem_g3g2 = G3 - G2;
if (abs(tem_g3g1)<=T )
{
score=(float)(G1+G3)/2;
}
if (abs(tem_g3g2)<=T)
{
score=(float)(G2+G3)/2;
}
if(abs(tem_g3g2)<=T && abs(tem_g3g1)<=T)
{
if (G3 - G1>=0 && G3 - G2>=0 )
score=(float)G3;
if (G2 - G1>=0 && G2 - G3>=0 )
score=(float)G2;
if (G1 - G2>=0 && G1 - G3>=0 )
score=(float)G1;
}
if(abs(tem_g3g2)>T && abs(tem_g3g1)>T)
score=(float)GJ;
}
cout<<fixed<<setprecision(1)<<score<<endl;  
}
return 0;

}


使用cmath的头文件,输出保留一位小数,对于初始输入可以定义为int型,float double应该也行,输出一定是float或是double的。

0 0
原创粉丝点击