Humidex
Time Limit: 1000MS | Memory Limit: 65536K |
Total Submissions: 17075 | Accepted: 6206 |
Description
Adapted from Wikipedia, the freeencyclopedia
The humidex is a measurement used byCanadian meteorologists to reflect the combined effect of heat and humidity. Itdiffers from the heat index used in the United States in using dew point ratherthan relative humidity.
When the temperature is 30°C (86°F) andthe dew point is 15°C (59°F), the humidex is 34 (note that humidex is adimensionless number, but that the number indicates an approximate temperaturein 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 theU.S. heat index at equal temperature and relative humidity.
The current formula for determining thehumidex was developed by J.M. Masterton and F.A. Richardson of Canada'sAtmospheric Environment Service in 1979.
According to the Meteorological Service ofCanada, a humidex of at least 40 causes "great discomfort" and above45 is "dangerous." When the humidex hits 54, heat stroke is imminent.
The record humidex in Canada occurred onJune 20, 1953, when Windsor, Ontario hit 52.1. (The residents of Windsor wouldnot 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 andToronto.
The humidex formula is as follows:
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) is2.718281828 raised to the exponent x.
While humidex is just a number, radioannouncers often announce it as if it were the temperature, e.g. "It's 47degrees out there ... [pause] .. with the humidex,". Sometimes weatherreports give the temperature and dewpoint, or the temperature and humidex, butrarely do they report all three measurements. Write a program that, given any twoof the measurements, will calculate the third.
You may assume that for all inputs, thetemperature, 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: aletter, a number, a second letter, and a second number. Each letter specifiesthe meaning of the number that follows it, and will be either T, indicatingtemperature, D, indicating dewpoint, or H, indicating humidex. The last line ofinput will consist of the single letter E.
Output
For each line ofinput except the last, produce one line of output. Each line of output shouldhave the form:
T number D number H number
where the threenumbers are replaced with the temperature, dewpoint, and humidex. Each valueshould be expressed rounded to the nearest tenth of a degree, with exactly onedigit 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
这道题逻辑思路很简单,主要是一些C++语法需要掌握:
1、setprecision
功能:控制输出流显示浮点数的数字个数,如果和fixed合用的话,可以控制小数点右面的位数
头文件:iomanip
程序例:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{cout<<12345.0<<endl;//输出12345
//cout<<fixed<<setprecision(2)<<123.456<<endl;/*如果在这个位置就加上fixed的话,后面的输出全部都按照fixed处理*/
cout << setprecision(4)<< 3.1415926 <<endl;//输出的结果是3.142
cout<<setprecision(3)<<12345.0<<endl;//输出的结果是 "1.23e+004 "
cout<<fixed<<setprecision(2)<<123.456<<endl;//输出的结果是123.46
cout<<showpoint<<12345.0<<endl;//输出12345.0
cout<<fixed<<setprecision(2)<<123.456<<endl;//输出的结果是123.46,要进行四舍五入
}
2、函数log,exp在头文件math中
C++:
#include<iostream>
#include<string.h>
#include<iomanip>
#include<math.h>
usingnamespace std;
intmain()
{
char a;
double t,d,h;
int i;
for(;;)
{
t=d=h=200;
for(i=0;i<2;i++)
{
cin>>a;
if(a=='E')
return 0;
else if(a=='T')
cin>>t;
else if(a=='D')
cin>>d;
else if(a=='H')
cin>>h;
}
if(t==200)
t=h-0.5555*((6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16)))))-10);
else if(d==200)
d=1/((1/273.16)-(log(((h-t)/0.5555+10)/(6.11)))/5417.7530)-273.16;
else if(h==200)
h=t+0.5555*((6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16)))))-10);
cout<<fixed<<setprecision(1)<<"T"<<t<<" "<<"D"<<d<<" "<<"H"<<h<<endl;
}
return 0;
}