传送门
题意:给temperature, dewpoint, humidex之中的两个数,然后求出第三个数,并输出
公式如下
humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]
exp(x) 是2.718281828x
先判断输入的是哪两个数,然后根据这两个数计算出另一个数
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#define N 10
#define E 2.718281828
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt", "r", stdin);
#endif
double t, d, h, t1, t2;
char c;
while(cin >> c){
t = d = h = -1.0;
if (c == 'E'){
break;
}
switch(c){
case 'T': cin >> t; break;
case 'D': cin >> d; break;
case 'H': cin >> h; break;
}
cin >> c;
switch(c){
case 'T': cin >> t; break;
case 'D': cin >> d; break;
case 'H': cin >> h; break;
}
if (h < 0){
h = t;
h += 0.5555 * ((6.11 * pow(E, (5417.7530*((1/273.16)-(1.0/(d+273.16)))))) - 10.0);
}else if (d < 0){
t1 = log(((h - t)/0.5555 + 10.0)/6.11)/5417.7530;
t1 = 1/273.16-t1;
t1 = 1/t1;
d = t1 - 273.16;
}else{
t = h - 0.5555 * ((6.11 * pow(E, (5417.7530*((1/273.16)-(1.0/(d+273.16)))))) - 10.0);
}
cout << fixed << setprecision(1) << "T " << t << " D " << d << " H " << h << endl;
}
return 0;
}