Advertisement
Sim0o0na

Untitled

Jun 6th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.Catch_the_Thief
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string type = Console.ReadLine();
  14.             int n = int.Parse(Console.ReadLine());
  15.             long currNum = 0;
  16.             long biggestValue = 0;
  17.             long closestNum = 0;
  18.  
  19.             for (int i = 1; i <= n; i++)
  20.             {
  21.                 if(type == "sbyte")
  22.                 {
  23.                     currNum = long.Parse(Console.ReadLine());
  24.                     if(currNum>=sbyte.MinValue && currNum <= sbyte.MaxValue)
  25.                     {
  26.                         if(currNum>closestNum && currNum<= sbyte.MaxValue)
  27.                         {
  28.                             closestNum = currNum;
  29.                         }
  30.                     }
  31.                 }
  32.                 else if(type == "int")
  33.                 {
  34.                     currNum = long.Parse(Console.ReadLine());
  35.                     if (currNum >= int.MinValue && currNum <= int.MaxValue)
  36.                     {
  37.                         if (currNum > closestNum && currNum <= int.MaxValue)
  38.                         {
  39.                             closestNum = currNum;
  40.                         }
  41.                     }
  42.                 }
  43.                 else if(type == "long")
  44.                 {
  45.                     currNum = long.Parse(Console.ReadLine());
  46.                     if (currNum >= long.MinValue && currNum <= long.MaxValue)
  47.                     {
  48.                         if (currNum > closestNum && currNum <= long.MaxValue)
  49.                         {
  50.                             closestNum = currNum;
  51.                         }
  52.                     }
  53.                 }
  54.  
  55.             }
  56.             switch (type)
  57.             {
  58.  
  59.                 case "sbyte":
  60.                     sbyte output1 = (sbyte)closestNum;
  61.                     Console.WriteLine(output1);
  62.                     break;
  63.                 case "int":
  64.                     int output2 = (int)closestNum;
  65.                     Console.WriteLine(output2);
  66.                     break;
  67.                 case "long":
  68.                     long output3 = (long)closestNum;
  69.                     Console.WriteLine(output3);
  70.                     break;
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement