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;

    • 水题,加油。

  • 相关阅读:
    php数据类型
    php输出语句
    php学习知识点框架
    php变量
    php语法
    php 的开发工具
    搭建php环境的几种方法
    redis 的单机安装
    三、其他主机安装zabbix-agent加入到zabbix
    内核参数优化
  • 原文地址:https://www.cnblogs.com/mojibake/p/15235628.html
Copyright © 2011-2022 走看看