Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Net.Sockets;
  3. using System.Net.Http;
  4. using System.Threading.Tasks;
  5. using System.IO;
  6. using System.Linq;
  7.  
  8. namespace Test
  9. {
  10.     public class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.             int n = int.Parse(Console.ReadLine()); // 5;
  15.  
  16.             int maxCapacity = 255; // This is the capacity of tank;
  17.  
  18.             int capacity = 0;
  19.  
  20.             for(int i = 0; i < n; i ++)
  21.             {
  22.                 int currentCapacity = int.Parse(Console.ReadLine()); // Litres of water we get everytime
  23.  
  24.                 if(capacity + currentCapacity <= maxCapacity)
  25.                 {
  26.                     capacity += currentCapacity;
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.WriteLine("Insufficient capacity!");
  31.                     continue;
  32.  
  33.                 }
  34.             }
  35.  
  36.             Console.WriteLine(capacity);
  37.  
  38.         }
  39.  
  40.     }
  41.        
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement