Advertisement
silvana1303

water overflow

May 25th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace exampreparation
  7. {
  8.     class exam
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int times = int.Parse(Console.ReadLine());
  13.             int sumwater = 0;
  14.             int capacity = 255;
  15.  
  16.             for (int i = 0; i < times; i++)
  17.             {
  18.                 int water = int.Parse(Console.ReadLine());
  19.  
  20.                 capacity -= water;
  21.  
  22.                 if (capacity < 0 )
  23.                 {
  24.                     Console.WriteLine("Insufficient capacity!");
  25.                     capacity += water;
  26.                    
  27.                 }
  28.                 else
  29.                 {
  30.                     sumwater += water;
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine(sumwater);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement