pku3299

简单的数学一元方程求解问题,分情况讨论即可.

题目中给出的是3个等式,最好将其中可以直接计算的部分算出,并且将其合并为一个方程,这样不仅可以减少运行中用于相同运算的时间,还有利于更好的求解.

不过,该题的一个关键点还是输入输出的处理.在使用cout.precision()时才发现它不是设定小数位数的,而是设定有效数字的位数,纠正一个错误.

Source:

#include<iostream>

#include<cmath>

#include<iomanip>

using namespace std;

 

void TD();

void TH();

void DH();

//humidex = temperature -5.555+ 3.394105*exp[19.833625-5417.753/(dewpoint+273.16)]

//

//h =3.394105*e - 5.555

//e =  exp [19.833625 - 5417.753/(dewpoint+273.16)]

 

double t,d,h,e;

 

int main()

{

    char ch;

    while(1)

    {

       ch=getchar();

       switch(ch)

       {

       case 'T':cin>>t;

           getchar();

           ch=getchar();

           switch(ch)

           {

           case 'D':cin>>d;

              TD();

              break;

           case 'H':cin>>h;

              TH();

              break;

           }

           getchar();

           break;

       case 'D':cin>>d;

           getchar();

           ch=getchar();

           switch(ch)

           {

           case 'T':cin>>t;

              TD();

              break;

           case 'H':cin>>h;

              DH();

              break;

           }

           getchar();

           break;

       case 'H':cin>>h;

           getchar();

           ch=getchar();

           switch(ch)

           {

           case 'T':cin>>t;

              TH();

              break;

           case 'D':cin>>d;

              DH();

              break;

           }

           getchar();

           break;

       case 'E':return 0;

       }

      

       cout.precision(3);

       cout.setf(ios::showpoint);

       cout.fill('0');

       //cout.width(4);

       cout<<"T "<<setw(4)<<t<<" D "<<setw(4)<<d<<" H "<<setw(4)<<h<<endl;

 

    }

    return 0;

   

}

 

void TD()

{

    e=3.394105*exp(19.833625-5417.75/(d+273.16));

    h=t+e-5.555;

}

 

void TH()

{

    d=5417.753/(19.833625-log((h-t+5.555)/3.394105))-273.16;

}

 

void DH()

{

    e=3.394105*exp(19.833625-5417.75/(d+273.16));

    t=h+5.555-e;

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值