题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823

1823. Ideal Gas

Time limit: 0.5 second

Memory limit: 64 MB
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 output
p = 1
n = 1
V = 1
T = 0.120279

Notes

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

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

最新文章

  1. Mybatis-Spring集成
  2. Python Day02
  3. Norflash控制器的Verilog建模之三(測試)
  4. 为什么没调用 didRegisterForRemoteNotificationsWithDeviceToken 和 didFailToRegisterForRemoteNotificationsWithError
  5. javascript编程: JSON, Mapping, 回调
  6. Java 设计一个贷款计算器 简易
  7. 安装Cocoapods(Pods 管理iOS 第三方库)
  8. Redis常用方法
  9. linux下查看硬件配置的相关命令
  10. C++ Iterator迭代器介绍及Iterator迭代器用法代码举例
  11. php面向对象编程学习之高级特性
  12. CSS了一个浮动导航条
  13. 在C++遇到有些关键字或者函数被弃用的情况
  14. Python-网络爬虫模块-requests模块之请求
  15. Java开发规范总结
  16. 常用Dockerfile举例
  17. Docker CE 镜像源站
  18. SQL注入之Sqli-labs系列第二十九关(基于WAF防护的单引号报错注入)
  19. 安卓 dex 通用脱壳技术研究(一)
  20. mingw 搭建Emscripten 环境

热门文章

  1. UNIX系统高级编程——第六章-系统数据文件和信息-总结
  2. 紫书 例题11-4 UVa247 (Floyd判断联通)
  3. 05003_Linux的基本命令
  4. Ubuntu设置显示桌面快捷键
  5. cocos2d_android 第一个游戏
  6. Android中的跨进程通信方法实例及特点分析(一):AIDL Service
  7. spfile
  8. Apache Bench测试
  9. Swift学习笔记(5):集合类型
  10. 验证备份集-使用DBVERIFY工具