您的位置:首页 > 编程语言 > C语言/C++

POJ 3299 Humidex

2017-09-05 17:03 441 查看
Adapted fromWikipedia, the free encyclopedia
The humidex is ameasurement used by Canadian meteorologists to reflect the combined effect ofheat and humidity. It differs from the heat index used in the United States inusing dew point rather than relative humidity.
When thetemperature 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 anapproximate temperature in C). If the temperature remains 30°C and the dewpoint
rises to 25°C (77°F), the humidex rises to 42.3.
The humidex tendsto be higher than the U.S. heat index at equal temperature and relativehumidity.
The currentformula for determining the humidex was developed by J.M. Masterton and F.A.Richardson of Canada's Atmospheric Environment Service in 1979.
According to theMeteorological Service of Canada, a humidex of at least 40 causes "greatdiscomfort" and above 45 is "dangerous." When the humidex hits54, heat stroke is imminent.
The record humidexin Canada occurred on June 20, 1953, when Windsor, Ontario hit 52.1. (Theresidents of Windsor would not have known this at the time, since the humidexhad yet to be invented.) More recently, the humidex reached 50 on July 14,
1995in both Windsor and Toronto.
The humidexformula 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) is 2.718281828 raised tothe exponent x.
While humidex isjust a number, radio announcers often announce it as if it were thetemperature, e.g. "It's 47 degrees out there ... [pause] .. with thehumidex,". Sometimes weather reports give the temperature and dewpoint, orthe temperature
and humidex, but rarely do they report all three measurements.Write a program that, given any two of the measurements, will calculate thethird.
You may assumethat for all inputs, the temperature, dewpoint, and humidex are all between-100°C and 100°C.
Input
Input will consistof a number of lines. Each line except the last will consist of four itemsseparated 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
beeither T, indicating temperature, D, indicating dewpoint, or H, indicatinghumidex. The last line of input will consist of the single letter E.
Output
For each line of input except the last, produce one lineof output. Each line of output should have the form:
T number D number H number
where the three numbers are replaced with thetemperature, dewpoint, and humidex. Each value should be expressed rounded tothe 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
 

题目主要主要就是根据公式:

humidex = temperature + h

h = (0.5555)× (e - 10.0)

e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]
输入其中任意两个量求解另外的量,这题主要的麻烦时输入….

C语言的scanf到现在我还是不太懂,建议直接用c++的输入输出把…..

代码:

 

//poj 3299
#define LOCAL
#include <cmath>
#include <cstdio>

int main(){
#ifdefLOCAL
freopen("in.txt","r",stdin);
#endif

doublen1,n2;
doublet=-200,d=-200,h=-200;
charc1,c2,c3;
while(scanf("%c",&c1)!=EOF&&c1!='E'){
double t=-200,d=-200,h=-200;
c3=getchar();//dealwith blank
scanf("%lf%c %lf",&n1,&c2,&n2);
c3= getchar();
if(c1=='T'){t=1;t=n1;}
if(c1=='D'){d=1;d=n1;}
if(c1=='H'){h=1;h=n1;}
if(c2=='T'){t=1;t=n2;}
if(c2=='D'){d=1;d=n2;}
if(c2=='H'){h=1;h=n2;}
if(t==-200) t=h-0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10.0);
if (d==-200) d=1/(1/273.16-log(((h-t)/0.5555+10)/6.11)/5417.753)-273.16;
if (h==-200)h=t+0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10.0);
printf("T %.1f D %.1f H %.1f\n",t,d,h);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oj poj c++