Advertisement
Guest User

CodingGame C# Third

a guest
Oct 2nd, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9.  * Auto-generated code below aims at helping you parse
  10.  * the standard input according to the problem statement.
  11.  **/
  12. class Solution
  13. {
  14.     static void Main(String[] args)
  15.     {
  16.         int N = int.Parse(Console.ReadLine()); // the number of temperatures to analyse
  17.         String TEMPS = Console.ReadLine(); // the N temperatures expressed as integers ranging from -273 to 5526
  18.        
  19.         if(TEMPS == null || TEMPS.Trim().Equals("")) {
  20.             Console.WriteLine("0");
  21.             return;
  22.         }
  23.        
  24.         String[] temperatures = TEMPS.Split(' ');
  25.         if(temperatures.Count() == 0) {
  26.             Console.WriteLine("0");
  27.             return;
  28.         }
  29.        
  30.         int t = Int32.Parse(temperatures[0]);
  31.        
  32.         for(int i = 1; i < temperatures.Count(); i++) {
  33.             int nt = Int32.Parse(temperatures[i]);
  34.            
  35.             if(Math.Abs(nt) == Math.Abs(t)) {
  36.                 if(t < 0) {
  37.                     t = nt;
  38.                 }
  39.             } else if(Math.Abs(nt) < Math.Abs(t)) {
  40.                 t = nt;
  41.             }
  42.         }
  43.        
  44.         Console.WriteLine(t);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement