题解 | Grading

#include<iostream>
#include<stdio.h>
using namespace std;
bool Insub(int a,int b,int sta) //判断是否在公差sta内
{
	int cha=0;
	if(a>b){
		cha=a-b;
		return (sta-cha)>=0?true:false;
	}
	else{
		cha=b-a;
		return (sta-cha)>=0?true:false;
	}
}
int max(int a,int b,int c){
	int temp=0;
	if(a>b)
	    temp=a;
	else
	    temp=b;
	if(temp>c)
	    return temp;
	else
	    return c;
}
int main(){
	int P,T,G1,G2,G3,Gj;
	float grade;
	bool flag=false;
	while(cin>>P>>T>>G1>>G2>>G3>>Gj){
		if(Insub(G1,G2,T)){
			grade=((float)G1+(float)G2)/2;
			flag=true;
		}
		else if(!flag&&Insub(G3,G1,T)&&!Insub(G3,G2,T)){
			grade=((float)G3+(float)G1)/2;
			flag=true;
		}
		else if(!flag&&!Insub(G3,G1,T)&&Insub(G3,G2,T)){
			grade=((float)G3+(float)G2)/2;
			flag=true;
		}
		else if(!flag&&Insub(G3,G1,T)&&Insub(G3,G2,T)){
			grade=max(G1,G2,G3);
			flag=true;
		}
		else if(!flag&&!Insub(G3,G1,T)&&!Insub(G3,G2,T)){
			grade=Gj;
			flag=true;
		}
		printf("%1.1f\n",grade);
	}
}

全部评论

相关推荐

投递Adobe等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务