Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mid.exam;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Problem3 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int[] priceRating = Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray();
- int entryPoint = Integer.parseInt(sc.nextLine());
- String type = sc.nextLine();
- int sumLeft = 0, sumRight = 0;
- for (int i = entryPoint-1; i >= 0; i--) {
- if(type.equals("cheap") && priceRating[i]<priceRating[entryPoint]){
- sumLeft += priceRating[i];
- }else if(type.equals("expensive") && priceRating[i]>=priceRating[entryPoint]){
- sumLeft += priceRating[i];
- }
- }
- for (int i = entryPoint+1; i < priceRating.length; i++) {
- if(type.equals("cheap") && priceRating[i]<priceRating[entryPoint]){
- sumRight += priceRating[i];
- }else if(type.equals("expensive") && priceRating[i]>=priceRating[entryPoint]){
- sumRight += priceRating[i];
- }
- }
- if (sumLeft>=sumRight){
- System.out.println("Left - " + sumLeft);
- }else{
- System.out.println("Right - " + sumRight);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement