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

    实现

    
    #include <cstdio>
    #include <vector>
    #include <algorithm>
    
    class window {
    
    public:  
        int x1,x2;
        int y1,y2;
        int id;
    
        window() {}
        window(int x1,int y1, int x2, int y2, int id) :
        x1(x1), y1(y1), x2(x2), y2(y2), id(id) {}
    
        bool inRange(int x, int y) {
            return (x1 <= x && x <= x2) && (y1 <= y && y <= y2);
        }
    
        int get_id() {
            return this->id;
        }
    
    };
    
    class Window_interaction {
    
    public:
        std::vector<window> windows;
    
        int id;
    
        Window_interaction() {
            id = 1;
        }
    
        void add_windows (int x1, int y1, int x2, int y2) {
            window one_window = window(x1,y1,x2,y2,this->id);
            this->id++;
            windows.insert(windows.begin(),one_window);
        }
    
        int response_click(int x, int y) {
            int response_id = 0;
            window click_window;
    
            std::vector<window>::iterator ite = windows.begin();
            for ( ;ite != windows.end(); ++ite) {
                if (ite->inRange(x,y)) {
                    response_id = ite->id;
                    click_window.x1 = ite->x1;
                    click_window.x2 = ite->x2;
                    click_window.y1 = ite->y1;
                    click_window.y2 = ite->y2;
                    click_window.id = ite->id;
                    windows.erase(ite);
                    break;
                }
            }
    
            if (response_id) {
                windows.insert(windows.begin(),click_window);
            }
            
            return response_id;
        }
    
    };
    
    int main() {
    
        int windows_num, click_num;
        Window_interaction win_interact;
        scanf("%d%d",&windows_num, &click_num);
    
        for(int i = 0;i < windows_num;++i) {
            int x1,y1,x2,y2;
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            win_interact.add_windows(x1,y1,x2,y2);
        }
    
        for (int i = 0;i < click_num;++i) {
            int x, y;
            scanf("%d%d",&x,&y);
    
            int response_id = win_interact.response_click(x,y);
            if (response_id) {
                printf("%d
    ",response_id);
            } else {
                printf("IGNORED
    ");
            }
        }
    
    
    }
    
    
    
  • 相关阅读:
    day06_02 继承
    day06_03 多继承区别
    day03_04 字符集编码转换
    day04_03 序列化与反序列化
    day04_06 单线程生成器的并行效果(协程)
    day04_02 装饰器 高阶版
    day04_05 内置方法
    复合控件的开发心得
    从子节点找父节点的循环sql
    asp中试用存储过程
  • 原文地址:https://www.cnblogs.com/amonqsq/p/13547815.html
Copyright © 2011-2022 走看看