URAL 1823 Ideal Gas

Source: Internet
Author: User

Test instructions

  

Know three variables to ask for one remaining variable. where r is the known constant = 8.314. Where v,t must be greater than 0. If there is a contradiction, output error. If an indeterminate condition occurs, the output undefined. It's a clever idea.
1#include <iostream>2#include <string.h>3#include <iomanip>4#include <algorithm>5 using namespacestd;6 DoubleR =8.314;7 inta[5];8 Chars1[Ten],s2[Ten];9 intInitCharstr[Ten])Ten { One     if(str[0]=='P')return 1; A     Else if(str[0]=='V')return 2; -     Else if(str[0]=='N')return 3; -     Else if(str[0]=='T')return 4;  the } - voidf () - { -     if(a[1]==0&& a[3]==0) cout<<"undefined"<<Endl; +     Else if(a[1]==0&& a[3]!=0) -     { +         if(a[2]==-1) cout<<"Error"<<Endl; A         if(a[3]==-1) cout<<"n = 0"<<Endl; at         if(a[4]==-1) cout<<"Error"<<Endl; -     } -     Else if(a[1]!=0&& a[3]==0) -     { -         if(a[1]==-1) cout<<"p = 0"<<Endl; -         if(a[2]==-1) cout<<"Error"<<Endl; in         if(a[4]==-1) cout<<"Error"<<Endl; -     } to     Else if(a[1]!=0&& a[3]!=0) +     { -         if(a[1]==-1) cout<<"p ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[3]*a[4]*r/a[2]<<Endl; the         if(a[2]==-1) cout<<"V ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[3]*a[4]*r/a[1]<<Endl; *         if(a[3]==-1) cout<<"n ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[1]*a[2]/(r*a[4]) <<Endl; $         if(a[4]==-1) Panax Notoginsengcout<<"T ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[1]*a[2]/(r*a[3]) <<Endl; -     } the      + } A intMain () the { +      -     intx; $     intT; $      while(cin>>s1>>s2>>t) -     { -memset (a,-1,sizeof(a)); thex =init (s1); -A[X] =T;WuyiCin>>s1>>s2>>T; thex =init (s1); -A[X] =T; WuCin>>s1>>s2>>T; -x =init (s1); AboutA[X] =T; $ f (); -     } -     return 0; -}
View Code

C + + reserved decimals

#include <iomanip>

cout<< "p =" <<setiosflags (ios::fixed) <<setprecision (6) << (double) a[3]*a[4]*r/a[2]<< Endl; (reserved six digits)

  

URAL 1823 Ideal Gas

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.