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 _18_DiffIntSize
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string[] Types;
- Dictionary<string, bool> Dict;
- CreateDict(out Types, out Dict);
- int counter = check(input, Dict);
- if (counter > 0)
- {
- Console.WriteLine($"{input} can fit in:");
- foreach (var item in Dict)
- {
- KeyValuePair<string, bool> kvp = item;
- if (kvp.Value == true)
- {
- Console.WriteLine($"* {kvp.Key}");
- }
- }
- }
- else
- {
- Console.WriteLine($"{input} can't fit in any type");
- }
- }
- private static void CreateDict(out string[] Types, out Dictionary<string, bool> Dict)
- {
- Types = new string[]
- {
- "sbyte", "byte", "short", "ushort", "int", "uint", "long"
- };
- Dict = new Dictionary<string, bool>();
- foreach (var item in Types)
- {
- Dict.Add(item, false);
- }
- }
- private static int check(string input, Dictionary<string, bool> dict)
- {
- int counter = 0;
- if (TryLong(input))
- {
- counter++;
- dict["long"] = true;
- }
- if (TryUInt(input))
- {
- counter++;
- dict["uint"] = true;
- }
- if (TryInt(input))
- {
- counter++;
- dict["int"] = true;
- }
- if (TryUshort(input))
- {
- counter++;
- dict["ushort"] = true;
- }
- if (TryShort(input))
- {
- counter++;
- dict["short"] = true;
- }
- if (TryByte(input))
- {
- counter++;
- dict["byte"] = true;
- }
- if (TrySbyte(input))
- {
- counter++;
- dict["sbyte"] = true;
- }
- return counter;
- }
- private static bool TryLong(string input)
- {
- bool longType = false;
- try
- {
- long N = long.Parse(input);
- longType = true;
- }
- catch (Exception)
- {
- longType = false;
- }
- return longType;
- }
- private static bool TryUInt(string input)
- {
- bool uIntType = false;
- try
- {
- uint N = uint.Parse(input);
- uIntType = true;
- }
- catch (Exception)
- {
- uIntType = false;
- }
- return uIntType;
- }
- private static bool TryInt(string input)
- {
- bool IntType = false;
- try
- {
- int N = int.Parse(input);
- IntType = true;
- }
- catch (Exception)
- {
- IntType = false;
- }
- return IntType;
- }
- private static bool TryUshort(string input)
- {
- bool ushortType = false;
- try
- {
- ushort N = ushort.Parse(input);
- ushortType = true;
- }
- catch (Exception)
- {
- ushortType = false;
- }
- return ushortType;
- }
- private static bool TryShort(string input)
- {
- bool shortType = false;
- try
- {
- short N = short.Parse(input);
- shortType = true;
- }
- catch (Exception)
- {
- shortType = false;
- }
- return shortType;
- }
- private static bool TryByte(string input)
- {
- bool byteType = false;
- try
- {
- byte N = byte.Parse(input);
- byteType = true;
- }
- catch (Exception)
- {
- byteType = false;
- }
- return byteType;
- }
- private static bool TrySbyte(string input)
- {
- bool sbyteType = false;
- try
- {
- sbyte N = sbyte.Parse(input);
- sbyteType = true;
- }
- catch (Exception)
- {
- sbyteType = false;
- }
- return sbyteType;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement