POJ3299Humidex(JAVA

Humidex是加拿大气象学家用来衡量高温和湿度组合影响的指标,不同于美国的热指数。该指数考虑了露点温度而非相对湿度。本文介绍了Humidex的计算公式以及与美国热指数的比较,并给出了当Humidex达到一定值时对人体舒适度的影响。还提供了一个程序,可以根据温度、露点或Humidex来计算缺失的参数。
摘要由CSDN通过智能技术生成

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.

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:

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.

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
import java.util.Scanner;
public class Main {

	static double exp=2.718281828;

	public static void main(String[] args) {
	        Scanner sc=new Scanner(System.in); 
	        while(sc.hasNext()) {

	        	double t=0;
	        	double d=0;
	        	double h=0;
	        	int flag=0,flag0=0;
	        	
	        	for (int i = 0; i < 2; i++) {//限制输入的字符
	        		String s=sc.next();
					if (s.equals("E")) {
					flag0=1;
					break;
				}else if (s.equals("T")) {
					t=sc.nextDouble();
					flag+=1;
				}else if (s.equals("D")) {
					d=sc.nextDouble();
					flag+=2;
				}else if (s.equals("H")) {
					h=sc.nextDouble();
					flag+=3;
				}
	        	}
	        	
	        	
	        	if (flag0==1) {break;}//当输出为E,结束程序
	        	
	        	if (flag==3) { //T+D
					h=t + 0.5555*(6.11 * Math.pow(exp,(5417.7530 * ((1/273.16) - (1/(d+273.16)))))-10.0);
				}else if (flag==4) {//T+H
					d=1/(1/273.16-Math.log(((h-t)/0.5555+10)/6.11)/5417.7530)-273.16;
				}else{//D+H
					t=h-0.5555*((6.11*Math.pow(exp, 5417.7530*((1/273.16)-1/(d+273.16))))-10.0);
				}
	        	System.out.println("T "+String.format("%.1f", t)+" D "+String.format("%.1f", d)+" H "+String.format("%.1f", h));
	        }
	   }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值