zoukankan      html  css  js  c++  java
  • 201403-2 窗口 Java


    要想到定义一个窗口类,判断点在不在矩形里好判断
    需要一个数组,存放结果

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    class Window{
    	int x1;
    	int y1;
    	int x2;
    	int y2;
    	int windowNum;//窗口顺序
    	public Window(int x1, int y1, int x2, int y2, int windowNum) {
    		super();
    		this.x1 = x1;
    		this.y1 = y1;
    		this.x2 = x2;
    		this.y2 = y2;
    		this.windowNum = windowNum;
    	}
    	//判断点在哪个窗口
    	public int inWindow(int x,int y) {
    		if(x >= this.x1 && x <= this.x2 && y >= this.y1 && y <=this.y2) {
    			return this.windowNum;
    		}else {
    			return 0;
    		}
    	}
    }
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();//N个窗口,先输入的在最底层
    		int M = sc.nextInt();//点击了几次
    		
    		List<Window> windows = new ArrayList<Window>();
    		
    		for(int i = 0;i<N;i++) {
    			windows.add(new Window(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),i+1));
    		}
    		//存放结果
    		String [] result = new String[M];
    		
    		int num = 0;
    		
    		for(int i = 0;i<M;i++) {
    			int x = sc.nextInt();
    			int y = sc.nextInt();
    			int j = windows.size() - 1;//最后一个打开的窗口在最前面
    			for(;j>=0;j--) {
    				Window currentWindow = windows.get(j);//获取当前窗口
    				int windowNum = currentWindow.inWindow(x, y);
    				if(windowNum > 0) {
    					result[num] = windowNum + "";//将被点击的窗口放到最前面
    					windows.add(currentWindow);
    					windows.remove(j);
    					break;
    				}
    			}
    			if(j < 0) {
    				result[num] = "IGNORED";
    			}
    			num++;
    		}
    		sc.close();
    		for(int i = 0;i<M;i++) {
    			System.out.println(result[i]);
    		}
    	}
    }
    
  • 相关阅读:
    谦谦君子 温润如玉
    [Linux: vim]vim自动生成html代码
    /boot/grub/grub.conf 内容诠释
    mini_httpd在RedHat 5下安装
    html 简单学习
    v4l
    手机处理器哪个好 智能手机处理器进化知识
    小败局】一位草根北漂创业者自述:赚钱的快餐店之死
    读书
    手游研发CJ抱大腿指南
  • 原文地址:https://www.cnblogs.com/yu-jiawei/p/12342912.html
Copyright © 2011-2022 走看看