POJ 3299 Humidex 水题

三个数,T表示温度 temperature,D表示露点 dewpoint,H表示湿润指数 humidex
三个数的关系:

1已知T和D求H
H = T + h
h = 0.5555 ( e 10.0 )
e = 6.11 e x p [ 5417.7530 1 273.16 1 D + 273.16 ]
2已知H和D求T
T = H h
h = 0.5555 ( e 10.0 )
$e=6.11*exp[5417.7530*\frac{1}{273.16}-\frac{1}{D+273.16}]¥
3已知T和H求D
h = H T
e = h 0.5555 t e m p
D = 1 1 273.16 l n ( e 6.11 ) 5417.7350 273.16

其中1是已经给出的,2和3需要自己根据1去推出,然后就是针对输入的两个数,去求出另外一个数就可以

代码如下:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
double t_and_d_to_h(double temperature, double dewpoint)
{
    double e = 6.11*exp(5417.7530*(1 / 273.16 - 1 / (dewpoint + 273.16)));
    double h = 0.5555*(e - 10.0);
    double humidex = temperature + h;
    return humidex;
}

double h_and_d_to_t(double humidex, double dewpoint)
{
    double e = 6.11*exp(5417.7530*(1 / 273.16 - 1 / (dewpoint + 273.16)));
    double h = 0.5555*(e - 10.0);
    double temperature = humidex - h;
    return temperature;
}

double t_and_h_to_d(double temperature, double humidex)
{
    double h = humidex - temperature;
    double e = h / 0.5555 + 10.0;
    double dewpoint = 1 / (1 / 273.16 - (log(e / 6.11) / 5417.7530)) - 273.16;
    return dewpoint;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    char A[3], B[3];
    double a, b, ans;
    while (scanf("%s %lf %s %lf", A, &a, B, &b) != EOF)
    {
        if (A[0] == 'E')
        {
            break;
        }
        if (A[0] == 'T'&&B[0] == 'D')
        {
            ans = t_and_d_to_h(a, b);
            printf("T %.1lf D %.1lf H %.1lf\n", a, b, ans);
        }
        if (A[0] == 'H'&&B[0] == 'D')
        {
            ans = h_and_d_to_t(a, b);
            printf("T %.1lf D %.1lf H %.1lf\n", ans, b, a);
        }
        if (A[0] == 'T'&&B[0] == 'H')
        {
            ans = t_and_h_to_d(a, b);
            printf("T %.1lf D %.1lf H %.1lf\n", a, ans, b);
        }
        if (A[0] == 'D'&&B[0] == 'T')
        {
            ans = t_and_d_to_h(b, a);
            printf("T %.1lf D %.1lf H %.1lf\n", b, a, ans);
        }
        if (A[0] == 'D'&&B[0] == 'H')
        {
            ans = h_and_d_to_t(b, a);
            printf("T %.1lf D %.1lf H %.1lf\n", ans, a, b);
        }
        if (A[0] == 'H'&&B[0] == 'T')
        {
            ans = t_and_h_to_d(b, a);
            printf("T %.1lf D %.1lf H %.1lf\n", b, ans, a);
        }
        //printf("%.1lf\n", ans);
    }
    //printf("end\n");
    //while (1);
    return 0;
}

这个用C++提交是AC的,但是如果用G++提交,需要将printf("T %.1f D %.1f H %.1f\n", a, b, ans);%.1lf换为%.1f,因为double类型在G++中需要用%f输出。

猜你喜欢

转载自blog.csdn.net/code12hour/article/details/81222790
今日推荐