URAL-1823 Ideal Gas (examining)

Source: Internet
Author: User

Ideal Gas
Time Limit: 500MS Memory Limit: 65536KB 64bit IO Format: %i64d &%i64u

Submit Status

Description

Many of know the universal method of solving simple physics problems:you has to find in a textbook an identity in WH Ich know the values of all the quantities except for one, substitute the numbers into this identity, and calculate the Unknown quantity. This problem is even easier. You know right away, the identity needed for its solution are the Clapeyron–mendeleev equation for the L Gas. This equation relates the pressure of a ideal gas  P, the amount of substance  N, the volume occupied by the gas  V, and the temperature  T. Given Three of these quantities, you has to find the fourth quantity. Note that the temperature of a gas and the volume occupied by it must always be positive.

Input

Each of the three input lines have the form "X = value", where  X is the symbol for a physical quantity and  value is a nonnegative an integer not exceeding 1000. The three lines specify the values of three different quantities. Pressure is specified in pascals, amount of substance in moles, volume in cubic meters, and temperature in kelvins. It is guaranteed, the temperature and volume are positive. The universal gas constant  R Should is taken equal to 8.314 J/(Mol K).

Output

If the input data is inconsistent, output the only line "error". If the value of  X Can is determined uniquely, output it in the format "X = value" with an accuracy of 10 ? 3. If it is impossible to uniquely determine the value of  X, output the only line "undefined".

Sample Input

input Output
p = 1n = 1V = 1
T = 0.120279
Notesrecall that Pa = n/m 2 and J = n· M.


The game did not come out, pay attention to examining, the difficulty when the output error,undefined,p=0 and n=0 to output undefined,p=0 to find N or n=0 for p, because T and V are positive, input errors, to output error.

#include <iostream> #include <iomanip>using namespace Std;const Double r = 8.314;int Main () {double p, V, N, t;ch AR 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 = n Um 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 = n Um 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 << setprecis Ion (6) << p << Endl; Continue }if (n = =-1) {n = (p*v)/(r*t) cout << ' n ' << ' << ' = ' << ' << fixed << setpre Cision (6) << n << Endl; Continue }if (v = =-1) {v = (n*r*t)/p; cout << ' V ' << ' << ' = ' << ' << fixed << setpreci Sion (6) << v << Endl; Continue }if (t = =-1) {T = (p*v)/(n*r) cout << ' t ' << ' << ' = ' << ' << fixed << setpre Cision (6) << T << Endl; Continue }}}


URAL-1823 Ideal Gas (examining)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.