-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperature.cs
More file actions
43 lines (38 loc) · 1.17 KB
/
Temperature.cs
File metadata and controls
43 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine()); // the number of temperatures to analyse
string[] inputs = Console.ReadLine().Split(' ');
int[] inp = new int[n];
int[] inp2 = new int[n];
for (int i = 0; i < n; i++)
{
inp[i] = int.Parse(inputs[i]); // a temperature expressed as an integer ranging from -273 to 5526
inp2[i] = Math.Abs(inp[i]);
}
if (inp2.Count() != 0)
{
int min = inp2.Min();
int ind = Array.IndexOf(inp2, min);
if (inp[ind] < 0)
{
bool b = Array.Exists(inp, element => element == -inp[ind]);
if (b) ind = Array.IndexOf(inp, min);
}
Console.WriteLine(inp[ind]);
}
else
{
Console.WriteLine("0");
}
}
}
}