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:
humidex = temperature + hwhere exp(x) is 2.718281828 raised to the exponent x.
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]
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
T number D number H numberwhere 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.
Sample Input
T 30 D 15 T 30.0 D 25.0 E
Sample Output
T 30.0 D 15.0 H 34.0 T 30.0 D 25.0 H 42.3
我认为难点在于由温度和湿度求露点,我使用的是书上看到的减半递推法,设露点的初始值为0,露点的增量从100,然后使用一个循环,由温度当前假设的露点值计算湿度,如果大于,则露点值减少一个增量,否则增加一个增量,每次计算后增量减半,直到增量小于等于0.0001
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 double e,h; 5 double wd,sd,ld; 6 7 void jse(double A){//计算e 8 e=6.11*exp(5417.7530*((1/273.16)-(1/(A+273.16)))); 9 } 10 11 void jsh(){//计算h 12 h=(0.5555)*(e-10.0); 13 } 14 15 double jssd(double b){//计算湿度,b为露点 16 double s; 17 jse(b); 18 jsh(); 19 s=wd+h; 20 return s; 21 } 22 23 void jswd(){//计算温度 24 jse(ld); 25 jsh(); 26 wd=sd-h; 27 } 28 29 void jsld(){//计算露点,湿度,温度已知 30 double i=100,sd1=sd; 31 for(ld=0;i>0.00001;i*=0.5){ 32 if(jssd(ld)>sd) ld-=i; 33 else ld+=i; 34 } 35 } 36 37 int main(void){ 38 double m,n; 39 char a,b; 40 while(scanf("%c %lf %c %lf",&a,&m,&b,&n)==4){ 41 wd=sd=ld=-101; 42 if(a=='T') wd=m; 43 else if(a=='H') sd=m; 44 else ld=m; 45 if(b=='T') wd=n; 46 else if(b=='H') sd=n; 47 else ld=n; 48 if(wd==-101) jswd(); 49 else if(sd==-101) sd=jssd(ld); 50 else jsld(); 51 printf("T %.1f D %.1f H %.1f ",wd,ld,sd); 52 scanf("%c",&a); 53 } 54 return 0; 55 }