Advertisement
MayaIP

Untitled

Jun 4th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 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 SolvingExpression
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. string type = Console.ReadLine();
  15. sbyte n = sbyte.Parse(Console.ReadLine());
  16. long maxnumber = long.MinValue;
  17. for (int i = 1; i <= n; i++)
  18. {
  19. var number = long.Parse(Console.ReadLine());
  20. switch (type)
  21. {
  22. case "sbyte":
  23. if (number <= sbyte.MaxValue && number > maxnumber)
  24. {
  25. maxnumber = number;
  26. }
  27. break;
  28. case "int":
  29. if (number <= int.MaxValue && number > maxnumber)
  30. {
  31. maxnumber = number;
  32. }
  33. break;
  34. case "long":
  35. if (number <= long.MaxValue && number > maxnumber)
  36. {
  37. maxnumber = number;
  38. }
  39. break;
  40. }
  41. }
  42. long sentence = 0;
  43. if (maxnumber >= 0)
  44. {
  45. sentence = (long)Math.Ceiling(Math.Abs((decimal)maxnumber / sbyte.MaxValue));
  46. }
  47. else
  48. {
  49. sentence = (long)Math.Ceiling(Math.Abs((decimal)maxnumber / sbyte.MinValue));
  50. }
  51. if (Math.Abs(sentence) <= 1)
  52. {
  53. Console.WriteLine($"Prisoner with id {maxnumber} is sentenced to {sentence} year");
  54. }
  55. else
  56. {
  57. Console.WriteLine($"Prisoner with id {maxnumber} is sentenced to {sentence} years");
  58. }
  59.  
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement