这个题主要就是读懂题目,考察英语水平,其实并不难理解,但是需要耐心,所以这里希望大家能够硬着头皮自己读题,我就不进行翻译了。这里领一个考察点就是保留一位小数。我将变量设为了float型,在printf中有一个用法可以设置输出数字的形式。即printf("%.1f",x);
#include <iostream>
#include <cmath>
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
float p;
float t;
float g1;
float g2;
float g3;
float gj;
int main(int argc, char** argv) {
while(scanf("%f%f%f%f%f%f",&p,&t,&g1,&g2,&g3,&gj)!=EOF){
//printf("%f %f %f %f %f %f\n",p,t,g1,g2,g3,gj);
if(abs(g1-g2)<=t){
gj=(g1+g2)/2;
// printf("%d\n",gj);
}
else{
// cout<<"我觉得不应该进来"<<endl;
if(abs(g1-g3)<=t&&abs(g2-g3)<=t){
gj=max(g1,g2);
gj=max(g3,gj);
}
else{
if(abs(g1-g3)<=t){
gj=(g1+g3)/2;
}
if(abs(g2-g3)<=t){
gj=(g2+g3)/2;
}
}
}
printf("%.1f\n",gj);
}
return 0;
}
京公网安备 11010502036488号