题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823
input | output |
---|---|
p = 1 n = 1 V = 1 |
T = 0.120279 |
PS:
p*V = n*R*T;
代码如下:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const double R = 8.314; double PP, VV, NN, TT; void findd(char a, double b) { if(a == 'p') { PP = b; } else if(a == 'V') { VV = b; } else if(a == 'n') { NN = b; } else if(a == 'T') { TT = b; } } int main() { char a; double b; while(~scanf("%c = %lf",&a, &b)) { getchar(); PP = VV = NN = TT = -1; findd(a,b); scanf("%c = %lf",&a, &b); getchar(); findd(a,b); scanf("%c = %lf",&a, &b); getchar(); findd(a,b); if(NN < 0) { printf("n = %lf\n",(PP*VV)/(R*TT)); } else if(PP < 0) { printf("p = %lf\n",(NN*R*TT)/(VV)); } else if(TT < 0 || VV < 0) { if(NN==0 && PP==0) { printf("undefined\n"); } else if(NN==0 || PP==0) { printf("error\n"); } else if(TT < 0) { printf("T = %lf\n",(PP*VV)/(NN*R)); } else if(VV < 0) { printf("V = %lf\n",(NN*R*TT)/(PP)); } } } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/44279393