标签:
Time Limit: 500MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
input | output |
---|---|
p = 1 n = 1 V = 1 |
T = 0.120279 |
比赛时没做出来,注意审题,难点在什么时候输出error,undefined,p=0且n=0时要输出undefined,p=0求n或n=0求p时,因为T和V为正,输入错误,要输出error。
#include<iostream> #include<iomanip> using namespace std; const double r = 8.314; int main() { double p, v, n, t; char type, op; double num; while (cin >> type) { p = v = n = t = -1; cin >> op; cin >> num; switch (type) { case 'p': p = num; break; case 'n': n = num; break; case 'V': v = num; break; case 'T': t = num; break; } cin >> type >> op >> num; switch (type) { case 'p': p = num; break; case 'n': n = num; break; case 'V': v = num; break; case 'T': t = num; break; } cin >> type >> op >> num; switch (type) { case 'p': p = num; break; case 'n': n = num; break; case 'V': v = num; break; case 'T': t = num; break; } if (p == 0 && n == 0) { cout << "undefined" << endl; continue; } if (p == 0 && n != -1 || n == 0 && p != -1){ cout << "error" << endl; continue; } if (p == -1) { p = (n*r*t) / v; cout << 'p' << ' ' << '=' << ' ' << fixed << setprecision(6) << p << endl; continue; } if (n == -1) { n = (p*v) / (r*t); cout << 'n' << ' ' << '=' << ' ' << fixed << setprecision(6) << n << endl; continue; } if (v == -1) { v = (n*r*t) / p; cout << 'V' << ' ' << '=' << ' ' << fixed << setprecision(6) << v << endl; continue; } if (t == -1) { t = (p*v) / (n*r); cout << 'T' << ' ' << '=' << ' ' << fixed << setprecision(6) << t << endl; continue; } } }
标签:
原文地址:http://blog.csdn.net/qq_18738333/article/details/45183889