码迷,mamicode.com
首页 > 其他好文 > 详细

URAL - 1823 Ideal Gas(审题)

时间:2015-04-22 09:36:59      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 500MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

 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

input output
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; }
	}
}


URAL - 1823 Ideal Gas(审题)

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45183889

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!