抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

题干

Adapted from Wikipedia, the free encyclopedia

The humidex is a measurement used by Canadian meteorologists to reflect the combined effect of heat and humidity. It differs from the heat index used in the United States in using dew point rather than relative humidity.

When the temperature is 30°C (86°F) and the dew point is 15°C (59°F), the humidex is 34 (note that humidex is a dimensionless number, but that the number indicates an approximate temperature in C). If the temperature remains 30°C and the dew point rises to 25°C (77°F), the humidex rises to 42.3.

The humidex tends to be higher than the U.S. heat index at equal temperature and relative humidity.

The current formula for determining the humidex was developed by J.M. Masterton and F.A. Richardson of Canada's Atmospheric Environment Service in 1979.

According to the Meteorological Service of Canada, a humidex of at least 40 causes "great discomfort" and above 45 is "dangerous." When the humidex hits 54, heat stroke is imminent.

The record humidex in Canada occurred on June 20, 1953, when Windsor, Ontario hit 52.1. (The residents of Windsor would not have known this at the time, since the humidex had yet to be invented.) More recently, the humidex reached 50 on July 14, 1995 in both Windsor and Toronto.

The humidex formula is as follows:

1
2
3
humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]

where exp(x) is 2.718281828 raised to the exponent x.

While humidex is just a number, radio announcers often announce it as if it were the temperature, e.g. "It's 47 degrees out there ... [pause] .. with the humidex,". Sometimes weather reports give the temperature and dewpoint, or the temperature and humidex, but rarely do they report all three measurements. Write a program that, given any two of the measurements, will calculate the third.

You may assume that for all inputs, the temperature, dewpoint, and humidex are all between -100°C and 100°C.


Input

Input will consist of a number of lines. Each line except the last will consist of four items separated by spaces: a letter, a number, a second letter, and a second number. Each letter specifies the meaning of the number that follows it, and will be either T, indicating temperature, D, indicating dewpoint, or H, indicating humidex. The last line of input will consist of the single letter E.

Output

For each line of input except the last, produce one line of output. Each line of output should have the form:

1
T number D number H number

where the three numbers are replaced with the temperature, dewpoint, and humidex. Each value should be expressed rounded to the nearest tenth of a degree, with exactly one digit after the decimal point. All temperatures are in degrees celsius.

改编自维基百科,免费百科全书

humidex是加拿大气象学家使用的一种测量方法,用来反映热量和湿度的综合影响。它与美国使用的热指数的不同之处在于使用露点而不是相对湿度。

当温度为30℃,露点为15℃时,湿度指数为34(湿度指数为无量纲数字,此处以C为单位表示近似温度),当温度保持在30℃,露点为25℃时,湿度指数为42.3。

在相同的温度和相对湿度下,湿度指数往往高于美国的热指数。

目前确定湿度的公式是由加拿大大气环境服务局的J.M.马斯特顿和F.A.理查森在1979年开发的。

根据加拿大气象局的说法,湿度至少为40会引起“极大的不适”,超过45则是“危险的”。当湿度达到54度时,中暑迫在眉睫。

加拿大的最高湿度记录发生在1953年6月20日,当时安大略省的温莎达到了52.1度。(当时温莎的居民还不知道这一点,因为湿度计还没有发明出来。)1995年7月14日,温莎和多伦多的湿度计都达到了50度。

humidex公式如下:

1
2
3
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.718281828的x次幂。

虽然湿度只是一个数字,但电台播音员经常把它当作温度来播报。“外面有47度……(停顿)…用humidex,”。有时天气预报会给出温度和露点,或者温度和湿度,但很少会同时报告这三种测量结果。编写一个程序,给定任意两个测量值,计算第三个。

您可以假设所有输入的温度、露点和湿度都在-100°C到100°C之间。


Input

输入将由许多行组成。除最后一行外,每行由四个项目组成,以空格分隔:一个字母、一个数字、第二个字母和第二个数字。每个字母指定了它后面的数字的含义,可以是T(表示温度),D(表示露点)或H(表示湿度)。最后一行输入将由单个字母E组成。

Output

对于除最后一行以外的每一行输入,生成一行输出。每一行的输出应该是这样的:

1
T number D number H number

其中三个数字替换为温度、露点和湿度。每个值应该四舍五入到最接近的十分之一度,小数点后正好有一位数字。所有的温度都以摄氏度为单位。

测试案例

Input

1
2
3
T 30 D 15
T 30.0 D 25.0
E

Output

1
2
T 30.0 D 15.0 H 34.0
T 30.0 D 25.0 H 42.3

题意与思路

题意大概就是给你一套公式,公式中包含三个变量:

  • 温度,用T表示
  • 露点,用D表示
  • 湿度,用H标识

要求你根据其中的两个量计算第三个量

1
2
3
humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]

本题对计算精度要求较高,须采用 double 作为数据类型。

经过推导,可以分别编写计算函数为:

由DH计算T

1
2
3
4
5
6
7
double DH2T(double D, double H){
double tmp = 5417.753000 / 273.160000;
double e = 6.110000 * exp(tmp * D / (D + 273.160000));
double h = 0.555500 * (e - 10.000000);
double T = H - h;
return T;
}

由DT计算H

1
2
3
4
5
6
7
double DT2H(double D, double T){
double tmp = 5417.753000 / 273.160000;
double e = 6.110000 * exp(tmp * D / (D + 273.160000));
double h = 0.555500 * (e - 10.000000);
double H = T + h;
return H;
}

由TH计算D

1
2
3
4
5
6
7
double TH2D(double T, double H){
double h = H - T;
double e = h / 0.555500 + 10.000000;
double exp_index = log(e / 6.110000);
double D = 1.000000 / (1.000000 / 273.160000 - exp_index / 5417.7530000) - 273.160000;
return D;
}

此外,由于摸不清它的测试案例对输入顺序是否有规定(例如是否一定是按照T、D、H的顺序输入),为避免不必要的Wrong Answer,采用重复 if...else 的笨办法判断了一下输入。

最后,还要注意限制输出的小数点位数:

1
printf("T %.1lf D %.1lf H %.1lf\n", T, D, H);

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

double DH2T(double D, double H){
double tmp = 5417.753000 / 273.160000;
double e = 6.110000 * exp(tmp * D / (D + 273.160000));
double h = 0.555500 * (e - 10.000000);
double T = H - h;
return T;
}

double DT2H(double D, double T){
double tmp = 5417.753000 / 273.160000;
double e = 6.110000 * exp(tmp * D / (D + 273.160000));
double h = 0.555500 * (e - 10.000000);
double H = T + h;
return H;
}

double TH2D(double T, double H){
double h = H - T;
double e = h / 0.555500 + 10.000000;
double exp_index = log(e / 6.110000);
double D = 1.000000 / (1.000000 / 273.160000 - exp_index / 5417.7530000) - 273.160000;
return D;
}

int main(){
char c1, c2;
double n1, n2;
double T, H, D;
cin>>c1;
while (c1 != 'E'){
cin>>n1>>c2>>n2;

if(c1 == 'T' && c2 == 'D'){
T = n1;
D = n2;
H = DT2H(D, T);
}

else if(c1 == 'D' && c2 == 'T'){
D = n1;
T = n2;
H = DT2H(D, T);
}


else if(c1 == 'D' && c2 == 'H'){
D = n1;
H = n2;
T = DH2T(D, H);
}

else if(c1 == 'H' && c2 == 'D'){
H = n1;
D = n2;
T = DH2T(D, H);
}

else if(c1 == 'T' && c2 == 'H'){
T = n1;
H = n2;
D = TH2D(T, H);
}

else if(c1 == 'H' && c2 == 'T'){
H = n1;
T = n2;
D = TH2D(T, H);
}

printf("T %.1lf D %.1lf H %.1lf\n", T, D, H);

cin>>c1;
}


return 0;
}

评论