What I've learnt:
setiosflags(ios::fixed)<<setprecision(1):fixed:将一个浮点数表示为一个定点整数和小数点和小数部分的格式;setprecision(1):小数部分的精度为1位
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;
const double E=2.718281828;
void cal_TD(double x,double y)
{
double e=6.11*pow(E,(5417.7530*((1/273.16)-(1/(y+273.16)))));
double h=(0.5555)*(e-10.0);
double humidex=x+h;
cout<<"T "<<setiosflags(ios::fixed)<<setprecision(1)<<x<<" "<<"D "<<setprecision(1)<<y<<" "<<"H "<<setprecision(1)<<humidex<<endl;
}
void cal_TH(double x,double y)
{
double h=y-x;
double e=h/(0.5555)+10.0;
double exponent=(log(e/6.11))/(log(E));
double dewpoint=1/((1/273.16)-(exponent/5417.7530))-273.16;
cout<<"T "<<setiosflags(ios::fixed)<<setprecision(1)<<x<<" "<<"D "<<setprecision(1)<<dewpoint<<" "<<"H "<<setprecision(1)<<y<<endl;
}
void cal_HD(double x,double y)
{
double e=6.11*pow(E,(5417.7530*((1/273.16)-(1/(y+273.16)))));
double h=(0.5555)*(e-10.0);
double temperature=x-h;
cout<<"T "<<setiosflags(ios::fixed)<<setprecision(1)<<temperature<<" "<<"D "<<setprecision(1)<<y<<" "<<"H "<<setprecision(1)<<x<<endl;
}
int main(int argc, const char * argv[]) {
char a,b;
double x,y;
while(cin>>a&&a!='E')
{
cin>>x>>b>>y;
if(a=='T'&&b=='D')
cal_TD(x,y);
if(a=='T'&&b=='H')
cal_TH(x, y);
if(a=='H'&&b=='D')
cal_HD(x,y);
if(a=='D'&&b=='T')
cal_TD(y,x);
if(a=='H'&&b=='T')
cal_TH(y,x);
if(a=='D'&&b=='H')
cal_HD(y,x);
}
return 0;
}