# POJ 3299 Humidex

1518人阅读 评论(0)

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

#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

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：89196次
• 积分：1455
• 等级：
• 排名：千里之外
• 原创：55篇
• 转载：0篇
• 译文：0篇
• 评论：17条
文章分类
评论排行
最新评论
友情链接