这个题还是算POJ中比较水的主要题意就是获得公式中3个变量中的其中2个然后求第三个。
humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]
WA了一次,不知道为什么POJ上g++,double输出的时候要用%f不能用%lf。。。
主要思想是将三个变量的权值区分开,分别为1,2,3.然后遍历输入的2个变量,将权值加起来,如果权值为3的话,输入的为前2个变量……以此类推。然后用一个map<char, double>存对应的变量名和值。
代码部分:
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
/********************************************//**
* humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]
*
***********************************************/
int main()
{
// freopen("1.txt", "r", stdin);
double dewpoint;
double temperature;
char ch[2];
while(cin >> ch[0] && ch[0] != 'E')
{
map<char, double> table;
cin >> temperature >> ch[1] >> dewpoint;
table[ch[0]] = temperature;
table[ch[1]] = dewpoint;
int flag = 0;
for(int i = 0; i < 2; ++i)
{
if(ch[i] == 'T')
flag += 1;
else if(ch[i] == 'D')
flag += 2;
else
flag += 3;
}
switch(flag)
{
case 3: //TD
{
double e = 6.11 * exp (5417.7530 *((1./273.16) - (1./(table['D'] + 273.16))));
double h = 0.5555 * (e - 10.0);
table['H'] = table['T'] + h;
}
break;
case 4://TH
{
double e = (table['H'] - table['T']) / 0.5555 + 10.0;
table['D'] = 1. / ((1./ 273.16) - log(e / 6.11) / 5417.7530) - 273.16;
}
break;
case 5://HD
{
double e = 6.11 * exp (5417.7530 *((1./273.16) - (1./(table['D'] + 273.16))));
double h = 0.5555 * (e - 10.0);
table['T'] = table['H'] - h;
}
break;
}
printf("T %.1f D %.1f H %.1f\n", table['T'], table['D'], table['H']);
}
return 0;
}