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") && verem.size() > 0) {
- priSor.add(verem.pop());
- } else {
- verem.push(event);
- }
- }
- String[] result = new String[priSor.size()];
- priSor.toArray(result);
- return result;
- }
- public static void main(String[] args) {
- String[] input = {"Aladar","Cecilia","Nekromanta","Bela","Nekromanta","Nekromanta","Denes","Balazs","Nekromanta","Agnes"};
- System.out.println(Arrays.toString(zombiesAreComing(input)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement