URAL 1823. Ideal gas (Math AH)

Source: Internet
Author: User

Title Link: http://acm.timus.ru/problem.aspx?space=1&num=1823


1823. Ideal Gastime limit:0.5 Second
Memory limit:64 MB
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. Inputeach of the three input lines has the form "X = value", where Xis the symbol for a physical quantity and valueis 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 RShould is taken equal to 8.314 J/(Mol K). Outputif the input data is inconsistent, output the only line "error". If the value of XCan 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 Output
p = 1n = 1V = 1
T = 0.120279
Notesrecall that Pa = n/m2and J = n· M.

Ps:

P*v = n*r*t;

The code is as follows:

#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;}


URAL 1823. Ideal gas (Math AH)

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.