SHARE
TWEET

Untitled

a guest Dec 9th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.         int n = Integer.parseInt(reader.readLine());
  11.         int[] mas = new int[n];
  12.         ArrayList<Integer> list = new ArrayList<Integer>();
  13.         String str = reader.readLine();
  14.         String strArr[] = str.split(" ");
  15.         for (int i = 0; i < strArr.length; i++) {
  16.             mas[i] = Integer.parseInt(strArr[i]);
  17.         }
  18.         for (int i = 0; i < mas.length; i++) {
  19.             list.add(i + 1);
  20.             if (mas[i] != 0) {
  21.                 list.add(mas[i]);
  22.             } else break;
  23.         }
  24.         for (int i = list.size() - 1; i >= 0; i--) {
  25.             System.out.print(list.remove(i)+" ");
  26.         }
  27.     }
  28. }
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
 
Top