zoukankan      html  css  js  c++  java
  • 【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;

    • 水题,加油。

  • 相关阅读:
    smb上传图片工具类
    hzero
    ORACLE
    数据库范式
    数据库设计阶段
    Java变量和运算符
    相对路径和绝对路径
    setTimeout()方法和setInterval()方法
    body onload()事件和table insertRow()、tr insertCell()
    eval函数和isNaN函数
  • 原文地址:https://www.cnblogs.com/mojibake/p/15235628.html
Copyright © 2011-2022 走看看