RFC

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
还是觉得写代码的能力太弱了,以致如果我不被人鄙视那真的是天理不容啊。从今天开始练习POJ,还是不要忙去做Uva等那些太有名的OJ吧。这次真的是想动真格的了,不然实力提升不上去啊。用Java写,因为我对java实在是太不熟了,主要的参考网站是这个。希望能给我带来好运^_^。从水题开始吧,Let's go.

POJ 3299

Input

Input will consist of a number of lines. Each line except the last will consist of four items separated by spaces: a letter, a number, a second letter, and a second number. Each letter specifies the meaning of the number that follows it, and will be either T, indicating temperature, D, indicating dewpoint, or H, indicating humidex. The last line of input will consist of the single letter E.

Output

For each line of input except the last, produce one line of output. Each line of output should have the form:
T number D number H number
where the three numbers are replaced with the temperature, dewpoint, and humidex. Each value should be expressed rounded to the nearest tenth of a degree, with exactly one digit after the decimal point. All temperatures are in degrees celsius.

用到的公式(正常显示下面的公式需要latex相关的插件支持TeX The World for Chromium;我实在不想用这样的插件,但是实在不知道有还有哪些好的):

[;h=t+tmp_1;]
[;tmp_1=0.555\cdot (tmp_2 - 10.0);]
[;tmp_2=6.11\cdot e^{5417.7530\cdot (\frac{1}{273.16}-\frac{1}{d+273.16})};]
 1 import java.util.Scanner;
2
3 public class Humidex {
4 static private double t, d, h;
5 static boolean te, de, he;
6
7 public static void reset() {
8 te = false;
9 de = false;
10 he = false;
11 }
12
13 public static void check(String str, Scanner sc) {
14 try {
15 if (str.equals("T")) {
16 t = sc.nextDouble();
17 te = true;
18 } else if (str.equals("D")) {
19 d = sc.nextDouble();
20 de = true;
21 } else if (str.equals("H")) {
22 h = sc.nextDouble();
23 he = true;
24 } else
25 throw new Exception();
26 } catch (Exception e) {
27 System.out.println("Wrong input");
28 }
29 }
30
31 public static void main(String[] args) {
32 String str;
33 int count = 0;
34 Scanner sc = new Scanner(System.in);
35 while (sc.hasNextLine()) {
36 reset();
37 if ((count & 1) == 0)
38 reset();
39 str = sc.next();
40 if (str.equals("E"))
41 return;
42 check(str, sc);
43 str = sc.next();
44 check(str, sc);
45 try {
46 if (te && de) {
47 double tmp = 6.11 * Math
48 .exp(5417.7530 * ((1 / 273.16) - (1 / (d + 273.16))));
49 h = t + 0.5555 * (tmp - 10.0);
50 } else if (te && he) {
51 d = 1 / (1 / 273.16 - Math
52 .log(((h - t) / 0.5555 + 10.0) / 6.11) / 5417.7530) - 273.16;
53
54 } else if (de && he) {
55 double tmp = 6.11 * Math
56 .exp(5417.7530 * ((1 / 273.16) - (1 / (d + 273.16))));
57 t = h - 0.5555 * (tmp - 10.0);
58 } else
59 throw new Exception();
60 } catch (Exception e) {
61 System.out.println("data not complete");
62 }
63 System.out.printf("T %.1f D %.1f H %.1f\n", t, d, h);
64 }
65 }
66 }

在解题过程中犯了几个错误需要改正:

1.对读入流的api掌握不好,这样用scanner的方法不好,毕竟每行的读入是很有规律的;

2.审题不严,致使开始忽略了Input提供的三种情况而只做了示例中的一种情况;

3.好多单词认不得,囧;

4.思路不清,写之前没有把各个步骤想一遍。

posted on 2012-03-04 21:06  hongxuchen  阅读(256)  评论(0编辑  收藏  举报
无觅相关文章插件,快速提升流量