地址:
http://ac.jobdu.com/problem.php?pid=1002
題目描述:
Grading hundreds of thousands of Graduate Entrance Exams is a hard work. It is even harder to design a process to make the results as fair as possible. One way is to assign each exam problem to 3 independent experts. If they do not agree to each other, a judge is invited to make the final decision. Now you are asked to write a program to help this process.
For each problem, there is a full-mark P and a tolerance T(<P) given. The grading rules are:
• A problem will first be assigned to 2 experts, to obtain G1 and G2. If the difference is within the tolerance, that is, if |G1 - G2| ≤ T, this problem's grade will be the average of G1 and G2.
• If the difference exceeds T, the 3rd expert will give G3.
• If G3 is within the tolerance with either G1 or G2, but NOT both, then this problem's grade will be the average of G3 and the closest grade.
• If G3 is within the tolerance with both G1 and G2, then this problem's grade will be the maximum of the three grades.
輸入:
Each input file may contain more than one test case.
Each case occupies a line containing six positive integers: P, T, G1, G2, G3, and GJ, as described in the problem. It is guaranteed that all the grades are valid, that is, in the interval [0, P].
輸出:
For each test case you should output the final grade of the problem in a line. The answer must be accurate to 1 decimal place.
樣例輸入:
20 2 15 13 10 18
樣例輸出:
14.0
來源:
2011年浙江大學計算機及軟件工程研究生機試真題
源碼:
#include<stdio.h>
float p, t, g1, g2, g3, gj;
float grade;
float ABS( float x ){ //求絕對值
if( x > 0 ){
return x;
}
else {
return -x;
}
}
int main(){
while( scanf( "%f %f %f %f %f %f", &p, &t, &g1, &g2, &g3, &gj) != EOF ){
if( g1 - g2 <= t && g1 - g2 >= -t ){ //g1給的分數和g2給的分數在可接受範圍
grade = (g1+g2)/2;
printf( "%.1f\n", grade );
continue;
}
else if( g3 - g1 <= t && g3 - g1 >= -t && g3 - g2 <= t && g3 - g2 >= -t ){ //g3給的分數和g1g2給的分數均在可接受範圍內
float maxmum = g1 > g2 ? g1 : g2;
maxmum = maxmum > g3 ? maxmum : g3; //找出三個中分數最大的那個
grade = maxmum;
printf( "%.1f\n", maxmum );
continue;
}
else if( (g3 - g1 <= t && g3 - g1 >= -t) || (g3 - g2 <= t && g3 - g2 >= -t) ){ //g3給的分數和g1或者g2給的分數在可接受範圍內(去除同時可在接受範圍內的情況)
float g3g1 = ABS( g3 - g1 );
float g3g2 = ABS( g3 - g2 );
if( g3g1 > g3g2 ){
grade = (g3+g2)/2;
printf( "%.1f\n", grade );
continue;
}
else{
grade = (g3+g1)/2;
printf( "%.1f\n", grade );
continue;
}
}
else{ //g3給的分數和g1或者g2給的均分數在可接受範圍內
grade = gj;
printf( "%.1f\n", grade );
continue;
}
}
}
/**************************************************************
Problem: 1002
User: 螺小旋
Language: C++
Result: Accepted
Time:0 ms
Memory:1020 kb
****************************************************************/