从今天开始刷POJ的题为考研机试做准备。
#include <iostream>
#include <string>
#include<math.h>
#include<iomanip>
using namespace std;
int main()
{
char alpha;
double t=200,d=200,h=200;
while(1){
for(int i=0;i<2;i++){
cin>>alpha;
if(alpha=='T')
cin>>t;
else if(alpha=='D')
cin>>d;
else if(alpha=='H')
cin>>h;
else if(alpha=='E')
return 0;
}
if(h==200)
h=0.5555*(6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16))))-10)+t;
else if(t==200)
t=h-0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);
else if(d==200)
d=1/((1/273.16)-((log((((h-t)/0.5555)+10.0)/6.11))/5417.7530))-273.16;
cout<<setprecision(1)<<fixed<<"T "<<t<<" D "<<d<<" H "<<h<<endl;
}
return 0;
}
其中setprecision()是控制输出流显示浮点数的有效数字个数,如果和fixed合用的话,可以控制小数点后面有几位。