Advertisement
Chronos_Ouroboros

Untitled

Mar 3rd, 2019
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 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[] inputs = Console.ReadLine().Split(' ');
  18.         if (n == 0) {
  19.             Console.WriteLine(0);
  20.             return;
  21.         }
  22.         int positive = 5527;
  23.         int negative = -274;
  24.         for (int i = 0; i < n; i++)
  25.         {
  26.             int t = int.Parse(inputs[i]); // a temperature expressed as an integer ranging from -273 to 5526
  27.             if (t == 0) {
  28.                 Console.WriteLine(0);
  29.                 return;
  30.             }
  31.             if (t > 0 && t < positive)
  32.                 positive = t;
  33.             else if (t < 0 && t > negative)
  34.                 negative = t;
  35.         }
  36.  
  37.         Console.WriteLine ((positive.CompareTo (Math.Abs (negative))) < 1 ? positive : negative);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement