Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package h_ExamPreparation.PreExam;
- import java.util.Scanner;
- public class BUS05 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // https://judge.softuni.bg/Contests/1103/Programming-Basics-Sample-Exam-16-December-2018
- int pax = Integer.parseInt(scanner.nextLine());
- int busStops = Integer.parseInt(scanner.nextLine());
- double oddPax = 0;
- double evenPax = 0;
- double totalPax = 0;
- for (int i = 1; i <= 2*busStops ; i++) {
- int n = Integer.parseInt(scanner.nextLine());
- if (i % 2 == 0){
- evenPax += n;
- }else {
- oddPax += n;
- }
- totalPax = pax + evenPax - oddPax;
- if (busStops % 2 != 0){
- totalPax += 2;
- }
- }
- System.out.printf("The final number of passengers is : %.0f",totalPax);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement