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