UVA 476

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=417

这题是给出某几个矩形的长和宽的坐标,然后输入点判断点是否在那些矩形里面,其中的x,y有些没按顺序输入   要自己调整

View Code
 1 #include<stdio.h>//本题关键在于输入给的数据只按xy的顺序,两个xy没按顺序
 2 #include<string.h>
 3 struct rec{
 4            double x1,y1,x2,y2;
 5           };//结构体保存矩形的descriptions
 6 int main()
 7 {
 8  struct rec r[20];
 9  int i=0,len=0,j,k,flag;
10  double x[10000],y[10000],temp;
11  char str[5];
12  while(scanf("%s",str),strcmp(str,"*"))
13      {
14       scanf("%lf%lf%lf%lf",&r[len].x1,&r[len].y1,&r[len].x2,&r[len].y2);
15       if(r[len].y1>r[len].y2)
16         {
17          temp=r[len].y1;
18          r[len].y1=r[len].y2;
19          r[len].y2=temp;
20         }
21       if(r[len].x1>r[len].x2)
22         {
23          temp=r[len].x1;
24          r[len].x1=r[len].x2;
25          r[len].x2=temp;
26         }//如果大小顺序变了要调整
27       len++;
28      }
29  while(scanf("%lf%lf",&x[i],&y[i]),(x[i]!=9999.9)||(y[i]!=9999.9))
30       i++;
31  for(j=0;j<i;j++)//遍历一次
32     {
33      flag=0;
34      for(k=0;k<len;k++)
35         {
36          if((x[j]>r[k].x1)&&(x[j]<r[k].x2)&&(y[j]>r[k].y1)&&(y[j]<r[k].y2))
37              {
38                printf("Point %d is contained in figure %d\n",j+1,k+1);
39                flag=1;//如果没有这个说明这个点不被任意图形包括
40              }
41         }
42      if(flag==0)
43         printf("Point %d is not contained in any figure\n",j+1);
44     }
45  return 0;
46 }

 

posted @ 2013-02-18 14:55  执着追求的IT小小鸟  阅读(236)  评论(0编辑  收藏  举报