九度oj题目1002:Grading
2014-03-30 16:59
295 查看
//不是说C语言就是C++的子集么,为毛printf在九度OJ上不能通过编译,abs还不支持参数为整型的abs()重载
//C++比较正确的做法是#include<cmath.h>,cout的格式输出需要用到#include<iomanip>库函数,具体为:cout<<fixed<<setprecision(1)<<score<<endl;结果保留一位小数
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int maxscore(int ,int ,int);
int main()
{
double p,t,g1,g2,g3,gj;
while(cin>>p>>t>>g1>>g2>>g3>>gj)
{
double score;
if(g1<=p&&g2<=p&&t<p)
{
if(abs(g1-g2)<=t)
{
score=(g1+g2)/2.0;
}else if(abs(g1-g3)<=t&&abs(g3-g2)<=t)
{
score=maxscore(g1,g2,g3);
}else if(abs(g1-g3)<=t||abs(g3-g2)<=t)
{
if(abs(g1-g3)<abs(g2-g3))
{
score=(g1+g3)/2.0;
}else
{
score=(g2+g3)/2.0;
}
}
else
{
score=gj;
}
}
cout<<fixed<<setprecision(1)<<score<<endl;
}
return 0;
}
int maxscore(int g1,int g2 ,int g3)
{
double score;
if(g1>g2)
{
if(g1>g3)
score=g1;
else
score=g3;
}else
{
if(g2>g3)
score=g2;
else
score=g3;
}
return score;
}
//C++比较正确的做法是#include<cmath.h>,cout的格式输出需要用到#include<iomanip>库函数,具体为:cout<<fixed<<setprecision(1)<<score<<endl;结果保留一位小数
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int maxscore(int ,int ,int);
int main()
{
double p,t,g1,g2,g3,gj;
while(cin>>p>>t>>g1>>g2>>g3>>gj)
{
double score;
if(g1<=p&&g2<=p&&t<p)
{
if(abs(g1-g2)<=t)
{
score=(g1+g2)/2.0;
}else if(abs(g1-g3)<=t&&abs(g3-g2)<=t)
{
score=maxscore(g1,g2,g3);
}else if(abs(g1-g3)<=t||abs(g3-g2)<=t)
{
if(abs(g1-g3)<abs(g2-g3))
{
score=(g1+g3)/2.0;
}else
{
score=(g2+g3)/2.0;
}
}
else
{
score=gj;
}
}
cout<<fixed<<setprecision(1)<<score<<endl;
}
return 0;
}
int maxscore(int g1,int g2 ,int g3)
{
double score;
if(g1>g2)
{
if(g1>g3)
score=g1;
else
score=g3;
}else
{
if(g2>g3)
score=g2;
else
score=g3;
}
return score;
}
相关文章推荐
- golang mac 获取当前应用程序目录,文件名,相对路径
- 用于二次开发企业即时通讯源码
- 返璞归真vc++之感言
- MySQL基础知识
- php设置session生存时间
- 监理单位资质 集成企业资质
- 用python实现各种排序算法
- SELinux
- 使用Handler对象引发空指针错误
- 算法导论 芯片检测问题之个人看法
- 收藏
- Java的23种设计模式详解
- 布局中以图换字的低级实现和高级实现
- Android为Button按钮添加监听事件的几种方式
- initrd映像文档的作用和制作
- 动态和静态顺序表【线性表(一)】
- 二元查找树变成排序的双向链表
- 《数据结构、算法与应用》1.(三次机会检测输入是否大于0)
- dedecms V5.7笔记:替换为kindeditor编辑器出现了乱码和栏目内容无法保存修改的解决方案
- 面向对象和面向过程的本质区别