http://acm.hit.edu.cn/hoj/problem/view?id=2695
给三个数字中的两个 根据公式计算出第三个
#include <stdio.h>
#include <math.h>
double solve_t(double d, double h);
double solve_d(double t, double h);
double solve_h(double t, double d);
int main()
{
double num1, num2;
char ch1, ch2;
double t, d, h;
while (scanf("%c", &ch1)!=EOF)
{
getchar();
if (ch1 == 'E')
break;
scanf("%lf %c %lf", &num1, &ch2, &num2);
getchar();
if (ch1 == 'T' && ch2 == 'D')
{
t = num1, d = num2;
h = solve_h(t, d);
}
else if(ch1 == 'D' && ch2 == 'T')
{
t = num2, d = num1;
h = solve_h(t, d);
}
else if(ch1 == 'T' && ch2 == 'H')
{
t = num1, h = num2;
d = solve_d(t, h);
}
else if(ch1 == 'H' && ch2 == 'T')
{
t = num2, h = num1;
d = solve_d(t, h);
}
else if(ch1 == 'D' && ch2 == 'H')
{
d = num1, h = num2;
t = solve_t(d, h);
}
else if(ch1 == 'H' && ch2 == 'D')
{
d = num2, h = num1;
t = solve_t(d, h);
}
printf("T %.1lf D %.1lf H %.1lf\n", t, d, h);
}
return 0;
}
double solve_t(double d, double h)
{
double e, t;
e = 6.11 * exp (5417.7530 * ((1/273.16) - (1/(d+273.16))));
t = h - (0.5555)*(e - 10.0);
return t;
}
double solve_d(double t, double h)
{
double e, d;
e = (h - t)/0.5555 +10;
d = 1 / (1 / 273.16 - ( log(e) - log(6.11) ) / 5417.7530) - 273.16;
return d;
}
double solve_h(double t, double d)
{
double e, h;
e = 6.11 * exp (5417.7530 * ((1/273.16) - (1/(d+273.16))));
h = t + (0.5555)*(e - 10.0);
return h;
}