【POJ】3299

时间:2021-09-06
本文章向大家介绍【POJ】3299,主要包括【POJ】3299使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Code

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

const double IMPOS = 1024;

char ch;
double t = IMPOS, d = IMPOS, e, h, humidex = IMPOS;

inline void modify(const char &flag){
    if(flag == 'T')cin >> t;
    if(flag == 'D')cin >> d;
    if(flag == 'H')cin >> humidex;
}

int main(int argc, char const *argv[]){
    ios::sync_with_stdio(false);
    while(true){
        cin >> ch;if(ch == 'E')return 0;else
        modify(ch);cin >> ch, modify(ch);
        if(t == IMPOS){
            t = humidex - 0.5555*(6.11*exp(5417.7530 * (1 / 273.16 - 1 / (d + 273.16))) - 10.0);
        }
        if(d == IMPOS){
            d = 1/(1/273.16 - log(((humidex - t)/0.5555 + 10)/6.11)/5417.1530) - 273.16;
        }
        if(humidex == IMPOS){
            humidex =  t + 0.5555 * (6.11 * exp(5417.7530 * (1 / 273.16 - 1/(d + 273.16))) - 10.0);
        }
        cout << "T " << fixed << setprecision(1) << t << " D " << d << " H " << humidex << endl;
        t = d = humidex = IMPOS;
    }
    return 0;
}

Review

  • <iostream>

    • 尽量ios::sync_with_stdio(false);
    • cin读取字符时忽略空白;
    • cout固定n位小数位数用<< fixed << setprecision(n) <<,需要#include <iomanip>
  • 限定了范围的变量,应该用超出范围的常数IMPOS表示,不能无脑0;

  • 水题,加油。

原文地址:https://www.cnblogs.com/mojibake/p/15235628.html