Advertisement
Guest User

6

a guest
Jun 8th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Linq;
  6.  
  7. using System.Text;
  8.  
  9. using System.Threading.Tasks;
  10.  
  11.  
  12.  
  13. namespace task10_Data_overflow
  14.  
  15. {
  16.  
  17.     class Program
  18.  
  19.     {
  20.  
  21.         static void Main(string[] args)
  22.  
  23.         {
  24.  
  25.             ulong num1 = ulong.Parse(Console.ReadLine());
  26.  
  27.             ulong num2 = ulong.Parse(Console.ReadLine());
  28.  
  29.  
  30.  
  31.             decimal minNum = Math.Min(num1, num2);
  32.  
  33.             decimal maxNum = Math.Max(num1, num2);
  34.  
  35.             decimal overflowValue = 0;
  36.  
  37.             string smallerType = string.Empty;
  38.  
  39.  
  40.  
  41.             if (minNum<=byte.MaxValue)
  42.  
  43.             {
  44.  
  45.                 overflowValue = byte.MaxValue;
  46.  
  47.                 smallerType = "byte";
  48.  
  49.             }
  50.  
  51.             else if (minNum<=ushort.MaxValue)
  52.  
  53.             {
  54.  
  55.                 overflowValue = ushort.MaxValue;
  56.  
  57.                 smallerType = "ushort";
  58.  
  59.             }
  60.  
  61.             else if (minNum <= uint.MaxValue)
  62.  
  63.             {
  64.  
  65.                 overflowValue = uint.MaxValue;
  66.  
  67.                 smallerType = "uint";
  68.  
  69.             }
  70.  
  71.             else if (minNum <= ulong.MaxValue)
  72.  
  73.             {
  74.  
  75.                 overflowValue = ulong.MaxValue;
  76.  
  77.                 smallerType = "ulong";
  78.  
  79.             }
  80.  
  81.  
  82.  
  83.             string maxType = string.Empty;
  84.  
  85.  
  86.  
  87.             if (maxNum<=byte.MaxValue)
  88.  
  89.             {
  90.  
  91.                 maxType = "byte";
  92.  
  93.             }
  94.  
  95.             else if(maxNum<=ushort.MaxValue)
  96.  
  97.             {
  98.  
  99.                 maxType = "ushort";
  100.  
  101.             }
  102.  
  103.             else if (maxNum <= uint.MaxValue)
  104.  
  105.             {
  106.  
  107.                 maxType = "uint";
  108.  
  109.             }
  110.  
  111.             else if (maxNum <= ulong.MaxValue)
  112.  
  113.             {
  114.  
  115.                 maxType = "ulong";
  116.  
  117.             }
  118.  
  119.  
  120.  
  121.             decimal overflowCount =  Math.Round(maxNum /overflowValue);
  122.  
  123.  
  124.  
  125.             Console.WriteLine($"bigger type: {maxType}");
  126.  
  127.             Console.WriteLine($"smaller type: {smallerType}");
  128.  
  129.             Console.WriteLine($"{maxNum} can overflow {smallerType} {Math.Ceiling(overflowCount)} times");
  130.  
  131.  
  132.  
  133.  
  134.  
  135.         }
  136.  
  137.     }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement