POJ 3299 Humidex

题目:三个变量temperature,dewpoint,humidex有以下关系:

humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]

任务是根据其中任意两个数,计算出第三个数。

输入:输入的每一行由四项组成,第一项为一个字符,第二项为一个数字,第三项为一个字符,第四项为数字,各项之间用空格分开,字符指出了后面的数字代表哪个变量,‘T’代表temperature,‘D’代表dewpoint, ‘H’代表humidex。最后一行输入仅包含一个字符‘E’。

输出:针对每行的输入,输出三个变量,输出的格式为: T number D number H number。

解题思路:该题简单,主要是利用公式进行计算。

代码:

#include<stdio.h>
#include<math.h>

float getHumidex(float temperature, float dewpoint)
{
	float humidex,h,e;
	e=6.11*exp(5417.7530*((1/273.16)-(1/(dewpoint+273.16))));
	h=0.5555*(e-10.0);
	humidex=temperature+h;
	return humidex;
}

float getTemperature(float dewpoint, float humidex)
{
	float temperature,h,e;
	e=6.11*exp(5417.7530*((1/273.16)-(1/(dewpoint+273.16))));
	h=0.5555*(e-10.0);
	temperature=humidex-h;
	return temperature;
}

float getDewpoint(float temperature, float humidex)
{
	float dewpoint,e,h;
	h = humidex-temperature;
	e=h/0.5555+10.0;
	dewpoint=1/((1/273.16)-log(e/6.11)/5417.7530) - 273.16;
	return dewpoint;
}


void calculate(float *temperature, float *dewpoint, float *humidex, int digit)
{
	switch(digit)
	{
		case 3: //已知 dewpoint, humidex
		*temperature = getTemperature(*dewpoint, *humidex);
		break;
		case 5: //已知 temperature, humidex
		*dewpoint = getDewpoint(*temperature, *humidex);
		break; 
		case 6: //已知 temperature, dewpoint
		*humidex = getHumidex(*temperature, *dewpoint);
		break;
	}
}

int main()
{
	float temperature, dewpoint, humidex, temp;
	char ch[2];
	int count=0,digit=0;
	scanf("%s",ch);
	while(ch[0] != 'E')
	{
		scanf("%f", &temp);
		count = (count+1)%2;
		if(ch[0] == 'T')
		{
		    temperature=temp;
		    digit += 4;
		}
		else if(ch[0] == 'D')
		{
			dewpoint=temp;
			digit += 2;
		}
		else if(ch[0] == 'H')
		{
			humidex=temp;
			digit += 1;
		}
		if(count==0) //输入了两个数,开始计算第三个数 
		{
			calculate(&temperature, &dewpoint, &humidex, digit);
			digit=0;
			printf("T %.1f D %.1f H %.1f\n", temperature, dewpoint, humidex);
		}
		
		scanf("%s",ch);
	}
	
	
	return 0;
}




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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值