您的位置:首页 > 其它

URAL - 1823 Ideal Gas(审题)

2015-04-22 01:01 288 查看
Ideal Gas

Time Limit: 500MSMemory Limit: 65536KB64bit IO Format: %I64d & %I64u
Submit Status

Description

Many of you know the universal method of solving simple physics problems: you have to find in a textbook an identity in which you 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 that the identity needed for its solution is the Clapeyron–Mendeleev equation for the state of an ideal gas. This equation relates the pressure of an 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 have 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 has the form “X = value”, where X is the symbol for a physical quantity and value is a nonnegative 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 that the temperature and volume are positive. The universal
gas constant R should be taken equal to 8.314 J / (mol · K).

Output

If the input data are inconsistent, output the only line “error”. If the value of X can be 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

inputoutput
p = 1
n = 1
V = 1

T = 0.120279

Notes

Recall that Pa = N / m 2 and J = N · m.

比赛时没做出来,注意审题,难点在什么时候输出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; }
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: