前几天水了poj上的第一个a+b,今天试着看百度上poj的刷题方法,试着做了下poj3299,最开始被一大堆看不懂的英文蒙住了,然后就谷歌翻译,然后又有道词典一起上,总算是把题意弄明白了

 

代码来自博客http://blog.csdn.net/lyy289065406/article/details/6642582

 

我开始做acm的题,的确自己的代码能力还很差,还需要加强,这个是我看到的这个题代码最短,含义最清楚的了,这种代码格式应该学习下

 

下面上代码:

题目的要求是输入2个值,然后求出全部的三个值,都是些数学的公式。

 1 //============================================================================
 2  // Name        : POJ.cpp
 3  // Author      : 
 4  // Version     : poj3299
 5  // Time        : 2012.11.1
 6  // Copyright   : Your copyright notice
 7  // Description : Hello World in C++, Ansi-style
 8  //============================================================================
 9  
10  #include <iostream>
11  #include<math.h>
12  #include<iomanip>
13  
14  using namespace std;
15  
16  
17  int main() {
18  
19      char alpha;
20      double t,d,h;
21      int i;  //输入变量计数
22  
23      for(;;){
24          t=d=h=200;    //三个参数的默认范围为-100~100
25          for(i = 0; i<2 ;i++){
26              cin>>alpha;
27              if(alpha=='E')
28                  return 0;  //程序退出
29              else if(alpha=='T')
30                  cin>>t;
31              else if(alpha=='D')
32                  cin>>d;
33              else if(alpha=='H')
34                  cin>>h;
35          }
36                if(h==200)
37                    h=t+0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);
38                  else if(t==200)
39                     t=h-0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);
40                  else if(d==200)
41                       d=1/((1/273.16)-((log((((h-t)/0.5555)+10.0)/6.11))/5417.7530))-273.16;
42  
43                cout<<setprecision(1)<<fixed<<"T "<<t<<" D "<<d<<" H "<<h<<endl;
44                //setprecision(1)格式化输出
45      }
46  
47  return 0;
48  }
49  
posted on 2012-11-01 20:43  _兜  阅读(1788)  评论(0编辑  收藏  举报