LardaX

DifferentIntegersSize

Sep 27th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace DifferentIntegersSize
  5. {
  6.     public class DifferentIntegersSize
  7.     {
  8.         public static void Main()
  9.         {
  10.             string input = Console.ReadLine();
  11.             bool isSByte = true;
  12.             bool isByte = true;
  13.             bool isShort = true;
  14.             bool isUShort = true;
  15.             bool isInt = true;
  16.             bool isUInt = true;
  17.             bool isLong = true;
  18.  
  19.             try
  20.             {
  21.                 long currentType = long.Parse(input);
  22.  
  23.  
  24.                 //Console.WriteLine("{0} can fit in: \n*sbyte\n*short\n*int\n*long", input);
  25.                 //return;
  26.             }
  27.             catch (Exception)
  28.             {
  29.                 isLong = false;
  30.             }
  31.  
  32.             try
  33.             {
  34.                 uint currentType = uint.Parse(input);
  35.             }
  36.             catch (Exception)
  37.             {
  38.                 isUInt = false;
  39.                
  40.             }
  41.             try
  42.             {
  43.                 int currentType = int.Parse(input);
  44.             }
  45.             catch (Exception)
  46.             {
  47.                 isInt = false;
  48.             }
  49.  
  50.             try
  51.             {
  52.                 ushort currentType = ushort.Parse(input);
  53.             }
  54.             catch (Exception)
  55.             {
  56.                 isUShort = false;
  57.             }
  58.  
  59.             try
  60.             {
  61.                 short currentType = short.Parse(input);
  62.             }
  63.             catch (Exception)
  64.             {
  65.                 isShort = false;
  66.             }
  67.  
  68.             try
  69.             {
  70.                 byte currentType = byte.Parse(input);
  71.             }
  72.             catch (Exception)
  73.             {
  74.                 isByte = false;
  75.             }
  76.  
  77.             try
  78.             {
  79.                 sbyte currentType = sbyte.Parse(input);
  80.             }
  81.             catch (Exception)
  82.             {
  83.                 isSByte = false;
  84.             }
  85.  
  86.             string output = "";
  87.             if (isLong)
  88.             {
  89.                 Console.WriteLine("{0} can fit in:", input);
  90.                 output += isSByte ? "* sbyte\n" : "";
  91.                 output += isByte ? "* byte\n" : "";
  92.                 output += isShort ? "* short\n" : "";
  93.                 output += isUShort ? "* ushort\n" : "";
  94.                 output += isInt ? "* int\n" : "";
  95.                 output += isUInt ? "* uint\n" : "";
  96.                 output += isLong ? "* long\n" : "";
  97.                 Console.WriteLine(output);
  98.             }
  99.             else
  100.             {
  101.                 Console.WriteLine("{0} can't fit in any type", input);
  102.             }
  103.             /*
  104.             string numAsString = Console.ReadLine();
  105.             BigInteger number;
  106.             bool numberFitsInBigInteger = BigInteger.TryParse(numAsString, out number);
  107.  
  108.             int lenght = numAsString.Length;
  109.            
  110.             if (number >= long.MinValue && number <= long.MaxValue)
  111.             {
  112.                 Console.WriteLine($"{numAsString} can fit in:");
  113.                 if (number >= sbyte.MinValue && number <= sbyte.MaxValue) Console.WriteLine("* sbyte");
  114.                 if (number >= byte.MinValue && number <= byte.MaxValue) Console.WriteLine("* byte");
  115.                 if (number >= short.MinValue && number <= short.MaxValue) Console.WriteLine("* short");
  116.                 if (number >= ushort.MinValue && number <= ushort.MaxValue) Console.WriteLine("* ushort");
  117.                 if (number >= int.MinValue && number <= int.MaxValue) Console.WriteLine("* int");
  118.                 if (number >= uint.MinValue && number <= uint.MaxValue) Console.WriteLine("* uint");
  119.                 if (number >= long.MinValue && number <= long.MaxValue) Console.WriteLine("* long");
  120.             }
  121.             else
  122.             {
  123.                 Console.WriteLine($"{numAsString} can't fit in any type");
  124.             }
  125.             */
  126.      
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment