SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Q5Lists;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.stream.Collectors;
  7.  
  8. public class Exc9 {
  9.     public static void main(String[] args) {
  10.         Scanner scan = new Scanner(System.in);
  11.         List<Integer> sequence = Arrays.stream(scan.nextLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList());
  12.         int sum = 0;
  13.         while (sequence.size() != 0) {
  14.             int index = Integer.parseInt(scan.nextLine());
  15.             if (0 <= index && index < sequence.size()) {
  16.                 int pokemon = sequence.get(index);
  17.                 sequence.remove(index);
  18.                 sum += pokemon;
  19.                 pokemonGo(sequence, index, pokemon);
  20.             } else if (index < 0) {
  21.                 sum += sequence.get(0);
  22.                 pokemonGo(sequence, 0);
  23.             } else {
  24.                 sum += sequence.get(sequence.size() - 1);
  25.                 pokemonGo(sequence, sequence.size() - 1);
  26.             }
  27.         }
  28.         System.out.println(sum);
  29.     }
  30.  
  31.     private static List pokemonGo(List<Integer> sequence, int index, int removed) {
  32.         for (int i = 0; i < sequence.size(); i++) {
  33.             if (sequence.get(i) <= removed) {
  34.                 sequence.set(i, sequence.get(i) + removed);
  35.             } else {
  36.                 sequence.set(i, sequence.get(i) - removed);
  37.             }
  38.         }
  39.         return sequence;
  40.     }
  41.  
  42.     private static List pokemonGo(List<Integer> sequence, int index) {
  43.         int removed = sequence.get(index);
  44.         sequence.set(sequence.size() - 1 - index, sequence.get(index));
  45.         for (int i = 0; i < sequence.size(); i++) {
  46.             if (sequence.get(i) <= removed) {
  47.                 sequence.set(i, sequence.get(i) + removed);
  48.             } else {
  49.                 sequence.set(i, sequence.get(i) - removed);
  50.             }
  51.         }
  52.         return sequence;
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top