Advertisement
Aseron

Alga_3_3/3 pont

Oct 13th, 2017
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 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")) {
  17.                 if(verem.size() > 0){
  18.                    
  19.                     priSor.offer(verem.pop());
  20.                    
  21.                 }
  22.             } else {
  23.                 verem.push(event);
  24.             }
  25.         }
  26.        
  27.         String[] result = new String[priSor.size()];
  28.        
  29.         int zombieSum = priSor.size();
  30.        
  31.         for(int i = 0; i<zombieSum; i++){
  32.             result[i] = priSor.remove();
  33.         }
  34.        
  35.     return result;
  36.     }
  37.    
  38.     public static void main(String[] args) {
  39.        
  40.         String[] input = {"Aladar","Cecilia","Nekromanta","Nekromanta","Bela","Denes","Balazs","Nekromanta","Agnes"};
  41.         System.out.println(Arrays.toString(zombiesAreComing(input)));
  42.    
  43.     }
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement