Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _10.Data_Overflow
- {
- class Program
- {
- static void Main(string[] args)
- {
- var a = ulong.Parse(Console.ReadLine());
- var b = ulong.Parse(Console.ReadLine());
- decimal overflow = 0.0m;
- ulong maxA = ulong.MaxValue;
- ulong maxB = ulong.MaxValue;
- string typeA = "ulong";
- string typeB = "ulong";
- if (byte.MinValue <= a && a <= byte.MaxValue)
- {
- a = (byte)a;
- maxA = byte.MaxValue;
- typeA = "byte";
- }
- else if (ushort.MinValue <= a && a <= ushort.MaxValue)
- {
- a = (ushort)a;
- maxA = ushort.MaxValue;
- typeA = "ushort";
- }
- else if (uint.MinValue <= a && a <= uint.MaxValue)
- {
- a = (uint)a;
- maxA = uint.MaxValue;
- typeA = "uint";
- }
- if (byte.MinValue <= b && b <= byte.MaxValue)
- {
- b = (byte)b;
- maxB = byte.MaxValue;
- typeB = "byte";
- }
- else if (ushort.MinValue <= b && b <= ushort.MaxValue)
- {
- b = (ushort)b;
- maxB = ushort.MaxValue;
- typeB = "ushort";
- }
- else if (uint.MinValue <= b && b <= uint.MaxValue)
- {
- b = (uint)b;
- maxB = uint.MaxValue;
- typeB = "uint";
- }
- if (a > b)
- {
- Console.WriteLine($"bigger type: {typeA}");
- Console.WriteLine($"smaller type: {typeB}");
- overflow = (decimal)a / maxB;
- Console.WriteLine($"{a} can overflow {typeB} {Math.Round(overflow)} times");
- }
- else
- {
- Console.WriteLine($"bigger type: {typeB}");
- Console.WriteLine($"smaller type: {typeA}");
- overflow = (decimal)b / maxA;
- Console.WriteLine($"{b} can overflow {typeA} {Math.Round(overflow)} times");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement