Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.PriorityQueue;
- import java.util.Stack;
- /**
- * @author ReeD
- */
- public class Alga3 {
- public static String[] zombiesAreComing(String[] events) {
- PriorityQueue<String> priSor = new PriorityQueue<>();
- Stack<String> verem = new Stack<>();
- for (String event : events) {
- if(event.equals("Nekromanta")) {
- if(verem.size() > 0){
- priSor.offer(verem.pop());
- }
- } else {
- verem.push(event);
- }
- }
- String[] result = new String[priSor.size()];
- int zombieSum = priSor.size();
- for(int i = 0; i<zombieSum; i++){
- result[i] = priSor.remove();
- }
- return result;
- }
- public static void main(String[] args) {
- String[] input = {"Aladar","Cecilia","Nekromanta","Nekromanta","Bela","Denes","Balazs","Nekromanta","Agnes"};
- System.out.println(Arrays.toString(zombiesAreComing(input)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement