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;
-
水题,加油。