标签:
题意:
1 #include <iostream> 2 #include <string.h> 3 #include <iomanip> 4 #include <algorithm> 5 using namespace std; 6 double R = 8.314; 7 int a[5]; 8 char s1[10],s2[10]; 9 int init(char str[10]) 10 { 11 if(str[0]==‘p‘) return 1; 12 else if(str[0]==‘V‘) return 2; 13 else if(str[0]==‘n‘) return 3; 14 else if(str[0]==‘T‘) return 4; 15 } 16 void f() 17 { 18 if(a[1]==0 && a[3]==0) cout<<"undefined"<<endl; 19 else if(a[1]==0 && a[3]!=0) 20 { 21 if(a[2]==-1) cout<<"error"<<endl; 22 if(a[3]==-1) cout<<"n = 0"<<endl; 23 if(a[4]==-1) cout<<"error"<<endl; 24 } 25 else if(a[1]!=0 && a[3]==0) 26 { 27 if(a[1]==-1) cout<<"p = 0"<<endl; 28 if(a[2]==-1) cout<<"error"<<endl; 29 if(a[4]==-1) cout<<"error"<<endl; 30 } 31 else if(a[1]!=0 && a[3]!=0) 32 { 33 if(a[1]==-1) cout<<"p = "<<setiosflags(ios::fixed)<<setprecision(6)<<(double)a[3]*a[4]*R/a[2]<<endl; 34 if(a[2]==-1) cout<<"V = "<<setiosflags(ios::fixed)<<setprecision(6)<<(double)a[3]*a[4]*R/a[1]<<endl; 35 if(a[3]==-1) cout<<"n = "<<setiosflags(ios::fixed)<<setprecision(6)<<(double)a[1]*a[2]/(R*a[4])<<endl; 36 if(a[4]==-1) 37 cout<<"T = "<<setiosflags(ios::fixed)<<setprecision(6)<<(double)a[1]*a[2]/(R*a[3])<<endl; 38 } 39 40 } 41 int main() 42 { 43 44 int x; 45 int t; 46 while(cin>>s1>>s2>>t) 47 { 48 memset(a,-1,sizeof(a)); 49 x = init(s1); 50 a[x] = t; 51 cin>>s1>>s2>>t; 52 x = init(s1); 53 a[x] = t; 54 cin>>s1>>s2>>t; 55 x = init(s1); 56 a[x] = t; 57 f(); 58 } 59 return 0; 60 }
c++保留小数
#include <iomanip>
cout<<"p = "<<setiosflags(ios::fixed)<<setprecision(6)<<(double)a[3]*a[4]*R/a[2]<<endl;(保留六位)
标签:
原文地址:http://www.cnblogs.com/yscc/p/4345599.html