Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaFundamentals.MidExam27_02;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class Problem3 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] numbers = Arrays.stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .toArray();
- int startingPoint = Integer.parseInt(scanner.nextLine());
- String input = scanner.nextLine();
- int itemValueSt = numbers[startingPoint];
- int leftSum = 0;
- int rightSum = 0;
- if ("cheap".equals(input)) {
- for (int i = startingPoint - 1; i >= 0; i--) {
- if (numbers[i] < itemValueSt) {
- leftSum += numbers[i];
- }
- }
- for (int i = startingPoint + 1; i < numbers.length; i++) {
- if (numbers[i] < itemValueSt) {
- rightSum += numbers[i];
- }
- }
- } else if ("expensive".equals(input)) {
- for (int i = startingPoint - 1; i >= 0; i--) {
- if (numbers[i] >= itemValueSt) {
- leftSum += numbers[i];
- }
- }
- for (int i = startingPoint + 1; i < numbers.length; i++) {
- if (numbers[i] >= itemValueSt) {
- rightSum += numbers[i];
- }
- }
- }
- if(rightSum > leftSum){
- System.out.println("Right - " + rightSum);
- }else {
- System.out.println("Left - " + leftSum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement