Advertisement
angelneychev

05. Bus

Oct 28th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 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 _05.Bus
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             int countPassengers = int.Parse(Console.ReadLine());
  15.             int busStops = int.Parse(Console.ReadLine());
  16.            
  17.            // int count = 1;
  18.             int sumPassengers = 0;
  19.             int ednPassengers = 0;
  20.  
  21.             for (int i = 1; i <= busStops; i++)
  22.             {
  23.                 int outPassengers = int.Parse(Console.ReadLine());
  24.                 int inPassengers = int.Parse(Console.ReadLine());
  25.  
  26.                 if (i % 2 != 0)
  27.                 {
  28.                     sumPassengers -= outPassengers;
  29.                     sumPassengers += inPassengers + 2;
  30.                 }
  31.                 else
  32.                 {
  33.                     sumPassengers -= outPassengers;
  34.                     sumPassengers += inPassengers - 2;
  35.                 }
  36.             }
  37.             ednPassengers = countPassengers + sumPassengers;
  38.             Console.WriteLine($"The final number of passengers is : {ednPassengers}");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement