Advertisement
cd62131

Print Max Temperature with Days

Dec 7th, 2013
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.94 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Map.Entry;
  3. import java.util.NavigableMap;
  4. import java.util.Scanner;
  5. import java.util.TreeMap;
  6. import java.util.TreeSet;
  7.  
  8. public class TemperatureSorter {
  9.   public static void main(String[] args) {
  10.     Scanner in = null;
  11.     try {
  12.       in = new Scanner(new File("kion.txt"));
  13.     }
  14.     catch (Exception e) {
  15.     }
  16.     NavigableMap<Double, TreeSet<Integer>> temperature =
  17.         new TreeMap<Double, TreeSet<Integer>>();
  18.     int day = 0;
  19.     while (in.hasNextLine()) {
  20.       double temp = .0;
  21.       try {
  22.         temp = new Double(in.nextLine());
  23.       }
  24.       catch (Exception e) {
  25.       }
  26.       if (temperature.get(temp) == null) temperature.put(temp, new TreeSet<Integer>());
  27.       temperature.get(temp).add(++day);
  28.     }
  29.     Entry<Double, TreeSet<Integer>> e = temperature.firstEntry();
  30.     for (int i: e.getValue()) {
  31.       System.out.println("" + i + "日: " + e.getKey());
  32.     }
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement