Advertisement
Aseron

Alga_3

Oct 13th, 2017
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.PriorityQueue;
  3. import java.util.Stack;
  4. /**
  5.  * @author ReeD
  6.  */
  7. public class Alga3 {
  8.  
  9.     public static String[] zombiesAreComing(String[] events) {
  10.        
  11.         PriorityQueue<String> priSor = new PriorityQueue<>();
  12.         Stack<String> verem = new Stack<>();
  13.  
  14.         for (String event : events) {
  15.  
  16.             if(event.equals("Nekromanta") && verem.size() > 0) {
  17.                 priSor.add(verem.pop());  
  18.             } else {
  19.                 verem.push(event);
  20.             }
  21.         }
  22.        
  23.         String[] result = new String[priSor.size()];
  24.        
  25.         priSor.toArray(result);
  26.  
  27.     return result;
  28.     }
  29.    
  30.     public static void main(String[] args) {
  31.        
  32.         String[] input = {"Aladar","Cecilia","Nekromanta","Bela","Nekromanta","Nekromanta","Denes","Balazs","Nekromanta","Agnes"};
  33.         System.out.println(Arrays.toString(zombiesAreComing(input)));
  34.    
  35.     }
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement