Guest User

Untitled

a guest
Jan 29th, 2017
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 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 _10.DataOverflow
  8. {
  9.     class DataOverflow
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             ulong firstNum = ulong.Parse(Console.ReadLine());
  14.             ulong secondNum = ulong.Parse(Console.ReadLine());
  15.  
  16.             ulong biggerNum = Math.Max(firstNum, secondNum);
  17.             ulong smallerNum = Math.Min(firstNum, secondNum);
  18.  
  19.             string bigType = "";
  20.             string smallType = "";
  21.             ulong smallNumType = 0;
  22.  
  23.             if (biggerNum >= smallerNum)
  24.             {
  25.                 if (biggerNum > byte.MinValue && biggerNum <= byte.MaxValue)
  26.                 {
  27.                     bigType = "byte";
  28.                 }
  29.                 else if (biggerNum > ushort.MinValue && biggerNum <= ushort.MaxValue)
  30.                 {
  31.                     bigType = "ushort";
  32.                 }
  33.                 else if (biggerNum > uint.MinValue && biggerNum <= uint.MaxValue)
  34.                 {
  35.                     bigType = "uint";
  36.                 }
  37.                 else if (biggerNum > ulong.MinValue && biggerNum <= ulong.MaxValue)
  38.                 {
  39.                     bigType = "ulong";
  40.                 }
  41.  
  42.                 if (smallerNum > byte.MinValue && smallerNum <= byte.MaxValue)
  43.                 {
  44.                     smallType = "byte";
  45.                     smallNumType = byte.MaxValue;
  46.                 }
  47.                 else if (smallerNum > ushort.MinValue && smallerNum <= ushort.MaxValue)
  48.                 {
  49.                     smallType = "ushort";
  50.                     smallNumType = ushort.MaxValue;
  51.                 }
  52.                 else if (smallerNum > uint.MinValue && smallerNum <= uint.MaxValue)
  53.                 {
  54.                     smallType = "uint";
  55.                     smallNumType = uint.MaxValue;
  56.                 }
  57.                 else if (smallerNum > ulong.MinValue && smallerNum <= ulong.MaxValue)
  58.                 {
  59.                     smallType = "ulong";
  60.                     smallNumType = ulong.MaxValue;
  61.                 }
  62.                
  63.                 Console.WriteLine($"bigger type: {bigType}");
  64.                 Console.WriteLine($"smaller type: {smallType}");
  65.                 Console.WriteLine($"{biggerNum} can overflow {smallType} {Math.Round((double)biggerNum / smallNumType)} times");
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment