好长时间没有写程序了,敲代码+调试花了我2个小时时间,就为了一道特简单题目(acm3299),以后要多多锻炼才行。
代码如下:
1#include <stdio.h>
2#include <math.h>
3
4const float E = 2.718281828;
5
6int main(int argc, char *argv[])
7{
8 float t, d, h, e, hh;
9 int index;
10 char temp;
11
12 while( (scanf("%c", &temp) == 1) && (temp != 'E'))
13 {
14 index = 0;
15 for( int i = 0 ; i < 2;i++)
16 {
17 switch(temp)
18 {
19 case 'T':
20 index |= 0x1;
21 scanf("%f", &t);
22 break;
23 case 'D':
24 index |= 0x2;
25 scanf("%f", &d);
26 break;
27 case 'H':
28 index |= 0x4;
29 scanf("%f", &h);
30 break;
31 default:
32 i--;
33 break;
34 }
35 scanf("%c",&temp);
36 }
37 switch(index)
38 {
39
40 case 3: // t d
41 e = 6.11 * exp(5417.7530*((1/273.16) -(1/(d+273.16))));
42 hh = (0.5555) * (e - 10.0);
43 h = t + hh;
44 break;
45 case 6: //d, h ----t
46 e = 6.11 * exp(5417.7530*((1/273.16) -(1/(d+273.16))));
47 t = h - 0.5555 * (e - 10.0);
48 break;
49 case 5: //t h ---d
50 double e;
51 e = (h-t)/0.5555 + 10.0;
52 d = 1/((1/273.16) - (log(e/6.11))/5417.753) - 273.16;
53 break;
54 }
55 printf("T %.1f D %.1f H %.1f\n", t, d, h);
56 }
57 return 0;
58}
59