Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class Pr2CarRace {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] numbers = Arrays
- .stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .toArray();
- double sumTimeCar1 = 0;
- double sumTimeCar2 = 0;
- for (int i = 0; i < numbers.length / 2; i++) {
- sumTimeCar1 += numbers[i];
- if (numbers[i] == 0) {
- sumTimeCar1 *= 0.8;
- }
- }
- for (int i = numbers.length - 1; i > numbers.length / 2; i--) {
- sumTimeCar2 += numbers[i];
- if (numbers[i] == 0) {
- sumTimeCar2 *= 0.8;
- }
- }
- if (sumTimeCar1 < sumTimeCar2) {
- System.out.println(String.format("The winner is left with total time: %.1f", sumTimeCar1));
- } else if (sumTimeCar2 < sumTimeCar1) {
- System.out.println(String.format("The winner is right with total time: %.1f", sumTimeCar2));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement