Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- String[] input = new String[] { "Aladar", "Cecilia", "Nekromanta", "Bela", "Nekromanta", "Nekromanta", "Denes", "Balazs",
- "Nekromanta", "Agnes", "Yildirim", "Sabri", "Sinan", "Nekromanta","Nekromanta", "Nekromanta" };
- String[] result = zombiesAreComing(input);
- for(int i =0; i<result.length;i++){
- System.out.println(result[i]);
- }
- }
- public static String[] zombiesAreComing(String[] events) {
- String[] asd = new String[events.length];
- int j =0;
- for(int i = 0; i< events.length;i++){
- if(events[i].equals("Nekromanta") && i!=0){
- if(events[i-1] == null){
- int a = i-1;
- while(events[a] == null && a>0 ){
- a--;
- }
- asd[j] = events[a];
- events[a]=null;
- events[i]=null;
- }
- else{
- asd[j]=events[i-1];
- events[i]=null;
- events[i-1]=null;
- }
- j++;
- }
- }
- String[] result = new String[j];
- for(int i = 0; i< j;i++){
- result[i]=asd[i];
- }
- Arrays.sort(result);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement