Advertisement
dragonbs

Water Overflow

Feb 2nd, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.33 KB | None | 0 0
  1. int iterations = int.Parse(Console.ReadLine());
  2.  
  3. byte capacity = 255;
  4. byte sum = 0;
  5.  
  6. for (int i = 0; i < iterations; i++)
  7. {
  8.     short liters = short.Parse(Console.ReadLine());
  9.     if (liters <= capacity - sum)
  10.     {
  11.         sum += (byte)liters;
  12.     }
  13.     else
  14.     {
  15.         Console.WriteLine("Insufficient capacity!");
  16.     }
  17. }
  18. Console.WriteLine(sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement