SUni2020

04. Bus

Mar 27th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Bus_04 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int startCount = Integer.parseInt(scanner.nextLine());
  8. int stops = Integer.parseInt(scanner.nextLine());
  9.  
  10. for (int stop = 1; stop <= stops ; stop++) {
  11. int outCount = Integer.parseInt(scanner.nextLine());
  12. int inCount = Integer.parseInt(scanner.nextLine());
  13.  
  14. startCount -= outCount;
  15. startCount += inCount;
  16.  
  17. if(stop % 2 == 1){
  18. startCount += 2;
  19. } else {
  20. startCount -= 2;
  21. }
  22. }
  23.  
  24. System.out.printf("The final number of passengers is : %d", startCount);
  25. }
  26. }
Add Comment
Please, Sign In to add comment