Advertisement
abhisekp

CodinGame - Temperatures

Jan 11th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1.         int closestTemp;
  2.        
  3.         if(N != 0) {
  4.             String TEMPS = in.nextLine(); // the N temperatures expressed as integers ranging from -273 to 5526
  5.             Scanner tempParse = new Scanner(TEMPS);
  6.             closestTemp = tempParse.nextInt(); // closest temperature
  7.             for(int count = 0; count < N-1; count++) {
  8.                 int temp = tempParse.nextInt();
  9.                 System.err.println("Temp = " + temp); // print temperature
  10.                 if(Math.abs(closestTemp) > Math.abs(temp) ||
  11.                 (Math.abs(closestTemp) == Math.abs(temp) && closestTemp < temp)) {
  12.                     closestTemp = temp;
  13.                 }
  14.             }
  15.         } else {
  16.             closestTemp = 0;
  17.         }
  18.  
  19.         System.out.println(closestTemp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement