/
P07_SentenceTheThief.cs
67 lines (61 loc) · 2.06 KB
/
P07_SentenceTheThief.cs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
namespace P07_SentenceTheThief
{
class P07_SentenceTheThief
{
static void Main(string[] args)
{
string dataTypeThiefID = Console.ReadLine();
byte countOfIDs = byte.Parse(Console.ReadLine());
long thiefID = long.MinValue;
while (countOfIDs > 0)
{
string currentID = Console.ReadLine();
if (dataTypeThiefID == "sbyte")
{
try
{
long currentIDNum = sbyte.Parse(currentID);
thiefID = Math.Max(currentIDNum, thiefID);
}
catch (Exception)
{
}
}
if (dataTypeThiefID == "int")
{
try
{
long currentIDNum = int.Parse(currentID);
thiefID = Math.Max(currentIDNum, thiefID);
}
catch (Exception)
{
}
}
if (dataTypeThiefID == "long")
{
try
{
long currentIDNum = long.Parse(currentID);
thiefID = Math.Max(currentIDNum, thiefID);
}
catch (Exception)
{
}
}
countOfIDs--;
}
if (thiefID > 0)
{
long sentence = (long) Math.Ceiling((decimal)thiefID / sbyte.MaxValue);
Console.WriteLine($"Prisoner with id {thiefID} is sentenced to {sentence} " + (sentence > 1 ? "years" : $"year"));
}
else
{
long sentence = (long)Math.Ceiling((decimal)thiefID / sbyte.MinValue);
Console.WriteLine($"Prisoner with id {thiefID} is sentenced to {sentence} " + (sentence > 1 ? "years" : $"year"));
}
}
}
}