poj3299:Humidex


poj3299:Humidex

题目很长,主要考数学和耐心...
给定一个公式,里面含有3个变量,给定其中任意两个求第三个,最后把3个变量都输出出来

#include
#include
#include
using namespace std;

const double NOIN = 200;	//用-100~100范围之外的数,标记未输入的一个变量
double d, t, h;


void judge(char letter, double num){
    if(letter == 'D'){
        d = num;
    }
    else if(letter == 'T'){
        t = num;
    }
    else{
        h = num;
    }
}

void Calc(){
    if(h == NOIN){     //get d and t, calc h
        double e = 6.11 * pow(2.718281828, 5417.7530 * ((1/273.16) - (1/(d+273.16))));
        double h1 = (0.5555)* (e - 10.0);
        h = t + h1;
    }
    else if(d == NOIN){ //get t and h, calc d
        double h1 = h - t;
        double e = h1 / (0.5555) + 10.0;
        d = 1.0/((1/273.16) - log(e/6.11)/5417.7530)-273.16;
    }
    else{   //get d and h, calc t
        double e = 6.11 * pow(2.718281828, 5417.7530 * ((1/273.16) - (1/(d+273.16))));
        double h1 = (0.5555)* (e - 10.0);
        t = h - h1;
    }
}


int main(){
    char letter1, letter2;
    double num1, num2;

    while(true){
        scanf("%c", &letter1);
        if(letter1 == 'E'){
            break;
        }
        scanf("%lf %c%lf", &num1, &letter2, &num2);
        getchar();	//注意输入处理
        d = t = h = NOIN;
        judge(letter1, num1);
        judge(letter2, num2);
        Calc();
        printf("T %.1f D %.1f H %.1f\n", t, d, h);
    }
    return 0;
}

相关