POJ 3299

上一道题做得太纠结,决定做道水题来缓解下。

Description

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 + 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.

题目好长,废话好多,可看百度知道简洁概要 http://zhidao.baidu.com/question/169409875.html

有H(humidex),D(dewpoint),T(humidex)三个值;
输入其中的两个值,然后通过
humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]
三个公式解出剩下的一个值,然后把三个都输出来。
最后以输入E结束输入。

虽然是道水题,但怎样写得最简洁也很关键。

http://blog.csdn.net/lyy289065406/article/details/6642582
#include<iostream>  
#include<math.h>  
#include<string>  
#include<iomanip>  
using namespace std;  
int main(void)  
{  
    char alpha;  
    double t,d,h;  
    int i;  
    for(;;)  
    {  
        t=d=h=200;    //三个参数的范围默认都是在-100 ~ 100  
        for(i=0;i<2;i++)  
        {  
            cin>>alpha;  
            if(alpha=='E')  
                return 0;  
            else if(alpha=='T')  
                cin>>t;  
            else if(alpha=='D')  
                cin>>d;  
            else if(alpha=='H')  
                cin>>h;  
        }  
        if(h==200)  
            h=t+0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);  
        else 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.0)/6.11))/5417.7530))-273.16;  
        cout<<setprecision(1)<<fixed<<"T "<<t<<" D "<<d<<" H "<<h<<endl;  
    }  
    return 0;  
}  

我本人是用JAVA写的,大同小异,主要是最后输出保留一位小数的时候稍微要留意下。

System.out.println("T " + String.format("%.1f", tNum)
                + " D " + String.format("%.1f", dNum)
                + " H " + String.format("%.1f", hNum));

最后,水题真开心~~

posted @ 2013-04-22 17:01  sillypudding  阅读(320)  评论(0编辑  收藏  举报