Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _10.DataOverflow
- {
- class Program
- {
- public static void Main()
- {
- var firstNum = decimal.Parse(Console.ReadLine());
- var secondNum = decimal.Parse(Console.ReadLine());
- //lowest
- var biggerNum = Math.Max(firstNum, secondNum);
- var smallerNum = Math.Min(firstNum, secondNum);
- var biggerType = string.Empty;
- var smallerType = string.Empty;
- //byteBigger
- if (byte.MinValue <= biggerNum && biggerNum <= byte.MaxValue)
- {
- biggerType = "byte";
- }
- //ushortBigger
- else if (ushort.MinValue <= biggerNum && biggerNum <= ushort.MaxValue)
- {
- biggerType = "ushort";
- }
- else if (uint.MinValue <= biggerNum && biggerNum <= uint.MaxValue)
- {
- biggerType = "uint";
- }
- else if (ulong.MinValue <= biggerNum && biggerNum <= ulong.MaxValue)
- {
- biggerType = "ulong";
- }
- //small
- if (byte.MinValue <= smallerNum && smallerNum <= byte.MaxValue)
- {
- smallerType = "byte";
- }
- //ushortBigger
- else if (ushort.MinValue <= smallerNum && smallerNum <= ushort.MaxValue)
- {
- smallerType = "ushort";
- }
- else if (uint.MinValue <= smallerNum && smallerNum <= uint.MaxValue)
- {
- smallerType = "uint";
- }
- else if (ulong.MinValue <= smallerNum && smallerNum <= ulong.MaxValue)
- {
- smallerType = "ulong";
- }
- Console.WriteLine("bigger type: {0}", biggerType);
- Console.WriteLine("smaller type: {0}", smallerType);
- //OverflowCheck
- var overflow = biggerNum;
- if (smallerType == "byte")
- {
- overflow = overflow / byte.MaxValue;
- Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
- }
- else if (smallerType == "ushort")
- {
- overflow = overflow / ushort.MaxValue;
- Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
- }
- else if (smallerType == "uint")
- {
- overflow = overflow / uint.MaxValue;
- Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
- }
- else if (smallerType == "ulong")
- {
- overflow = overflow / ulong.MaxValue;
- Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement