2020-08-21

201403-2  窗口  java 满分 ccf csp认证考试

我尝试了一下栈,接触java不久。写的比较乱,希望大家多多包涵。不足之处,也渴望得到大家的指导。


import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	     int N = sc.nextInt();
	     int M = sc.nextInt();String[] a = new String[M]; 
	     
	     Stack stack = new Stack<>();
	     Window[] w = new Window[N]; 
	     for (int i = 1; i < N+1; i++) {
	    	 
			w[i-1] = new Window(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),i);
			stack.push(w[i-1]);
		}
	     int bol = 2;
	     for (int i = 0; i < M; i++) {
			int x = sc.nextInt();int y = sc.nextInt();
			for(int j = N-1;j>=0;j--){
				Window ww = stack.get(j);
				bol = 0;
				if(ww.click(x, y)){
					a[i] = ww.number+"";
					stack.remove(j);
					stack.push(ww);
					bol = 1;
					break;
				}
			}
			if(bol == 0){
				a[i] = "IGNORED";
			}
			
		}
	     for (int i = 0; i < a.length; i++) {
			System.out.println(a[i]);
		}
	}
}
class Window{
	int x1,x2,y1,y2;
	int number;
	public Window(int x1,int y1,int x2,int y2,int number){
		this.x1 = x1;this.x2 = x2;
		this.y1 = y1;this.y2 = y2;this.number = number;
	}
	public boolean click(int x,int y){
		if(x1<=x&&x<=x2&&y1<=y&&y2>=y){
			return true;
		}else
			return false;
	}
	
	
}

 

你可能感兴趣的:(2020-08-21)