[POJ]3299-Humidex[初投稿]

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;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值