九度OJ 1002 Grading

题目描述:
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(

#include 
using namespace std;
/*
20 2 15 13 10 18
18 2 18 15 16 17
18 2 18 15 17 29
18 1 19 23 21 22
*/
double abs(double x){
    return x >= 0 ? x : -x;
}
int main(){
    char buffer[256];
    while(gets(buffer)){
        double P,T,G1,G2,G3,GJ;
        double result;
        sscanf(buffer,"%lf %lf %lf %lf %lf %lf",&P,&T,&G1,&G2,&G3,&GJ);
        if(abs(G1 - G2) <= T){
            result = (G1 + G2)/2;
        }else{
            int state = 0;
            if(G3 <= G1+T && G3 >= G1-T)state += 1;
            if(G3 <= G2+T && G3 >= G2-T)state += 2;
            switch(state){
                case 0:{result = GJ;
                        break;}
                case 1:{result = (G1 + G3)/2;
                        break;}
                case 2:{result = (G3 + G2)/2;
                        break;}
                case 3:{result = (G1 >= G1)? G1 : G2;
                        break;}
            }
        }
        printf("%.1f\n",result);
    }
    return 0;
}

你可能感兴趣的:(OJ)