北航计算机2015年复试-机试第2题

/*今天是北航2015年机试第二题,
题目。模拟鼠标点击时桌面的窗口叠放次序。
先输入一个数字n,表示桌面窗口的数量,再输入n行,每行5个数,
分别为窗口ID,窗口左下角横坐标,左下角纵坐标,右上角横坐标,右上角纵坐标
(坐标均以屏幕左下角为0点,即第一象限)
先输入的窗口叠放在后输入的窗口上面。
再输入m行,表示m次点击,每行两个数,分别标识点击的横坐标和纵坐标
要求按窗口叠放次序从高到低依次输出窗口的ID
例,
输入:
2
1 5 1 1 5
2 7 1 3 5
3
1 2
4 3
6 4
输出:2 1*/
#include <stdio.h>
#define max 100
struct coordinate{
	int x;
	int y;
}shubiao[max];
struct window{
	struct coordinate leftDown;
	struct coordinate rightUp;
	int layer;//层次为0标识在最上层,层次数字越大,表示越在下面
	int id;
}windows[max];

//判断鼠标点击的区域是否是在窗口内部
int IsInside(struct coordinate zuobiao,struct window w){
	int x,y;
	x=zuobiao.x;
	y=zuobiao.y;
	if(x>w.leftDown.x&&x<w.rightUp.x&&y>w.leftDown.y&&y<w.rightUp.y){
		return 1;
	}
	else{
		return 0;
	}
}
void paixu(struct window w[],int wCount){
	int i,j;
	for(i=0;i<wCount;i++){
		for(j=i;j<wCount;j++){
			if(w[i].layer>w[j].layer){
				struct window temp;
				temp=w[i];
				w[i]=w[j];
				w[j]=temp;
			}
		}
	}
}
void main(){
	int n=0,m=0,i=0,j=0,t=0,windowsCount=0,shubiaoCount=0,layer=0;
	printf("-------窗口------\n");
	scanf("%d",&n);
	windowsCount=n;
	while(n){
		scanf("%d%d%d%d%d",&windows[i].id,&windows[i].leftDown.x,&windows[i].leftDown.y,
			&windows[i].rightUp.x,&windows[i].rightUp.y);
		windows[i].layer=layer++; //初始化,按输入先后,决定层次
		i++;
		n--;
	}
	printf("------鼠标点击------\n");
	scanf("%d",&m);
	shubiaoCount=m;
	i=0;
	while(m){
		scanf("%d%d",&shubiao[i].x,&shubiao[i].y);
		i++;
		m--;
	}
	m=shubiaoCount;
	for(i=0;i<shubiaoCount;i++){
		for(j=0;j<windowsCount;j++){
			if(IsInside(shubiao[i],windows[j])&&windows[j].layer==0){
				break;
			}
			else if(IsInside(shubiao[i],windows[j])&&windows[j].layer!=0){
				for(t=0;t<windowsCount;t++){
					if(windows[t].layer==0){
						windows[t].layer=windows[j].layer;
						break;
					}
				}
				windows[j].layer=0;
			}
		}
	}
	paixu(windows,windowsCount);
	for(i=0;i<windowsCount;i++){
		printf("%d  ",windows[i].id);
	}
	printf("\n");
	
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值