Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AsteroidColision {
- public static void collision(Stack<Integer> stack){
- ArrayStack<Integer> pom=new ArrayStack<>(100);
- while(!stack.isEmpty()){
- int num1=stack.pop();
- if(stack.isEmpty()) {
- stack.push(num1);
- break;
- }
- int num2=stack.pop();
- if((num1>0 && num2<0) || (num1<0 && num2>0)){
- if(Math.abs(num1) > Math.abs(num2)){
- stack.push(num1);
- }
- else if(Math.abs(num1) < Math.abs(num2)){
- stack.push(num2);
- }
- }
- else{
- stack.push(num2);
- pom.push(num1);
- }
- }
- while (!stack.isEmpty()){
- pom.push(stack.pop());
- }
- if (pom.isEmpty())
- System.out.println("none");
- while (!pom.isEmpty()){
- System.out.println(pom.pop());
- }
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- int n=in.nextInt();
- ArrayStack<Integer> stack=new ArrayStack<>(100);
- for(int i=0;i<n;i++){
- stack.push(in.nextInt());
- }
- collision(stack);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement