Advertisement
kalin729

Mid Exam 3

Jul 10th, 2021 (edited)
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package mid.exam;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class Problem3 {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         int[] priceRating = Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray();
  11.         int entryPoint = Integer.parseInt(sc.nextLine());
  12.         String type = sc.nextLine();
  13.         int sumLeft = 0, sumRight = 0;
  14.  
  15.         for (int i = entryPoint-1; i >= 0; i--) {
  16.             if(type.equals("cheap") && priceRating[i]<priceRating[entryPoint]){
  17.                 sumLeft += priceRating[i];
  18.             }else if(type.equals("expensive") && priceRating[i]>=priceRating[entryPoint]){
  19.                 sumLeft += priceRating[i];
  20.             }
  21.         }
  22.  
  23.         for (int i = entryPoint+1; i < priceRating.length; i++) {
  24.             if(type.equals("cheap") && priceRating[i]<priceRating[entryPoint]){
  25.                 sumRight += priceRating[i];
  26.             }else if(type.equals("expensive") && priceRating[i]>=priceRating[entryPoint]){
  27.                 sumRight += priceRating[i];
  28.             }
  29.         }
  30.  
  31.         if (sumLeft>=sumRight){
  32.             System.out.println("Left - " + sumLeft);
  33.         }else{
  34.             System.out.println("Right - " + sumRight);
  35.         }
  36.  
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement