朱色虫居
Pages
Home
Featured Posts
2006/09/08
476-Points in Figures: Rectangles
<br /> /* <br /> "Points in Figures: Rectangles"<br /> Level:3.0<br /> Date:2006/9/7<br /> 技巧:<br /> 長方形的判斷: x > 左上角的x && x < 右下角的x && y < 左上角的y && y > 右下角的y <br /> */<br /> <br /> #include <stdio.h><br /> struct rectangle{<br /> double upperLeft_X;<br /> double upperLeft_Y;<br /> double lowerRight_X;<br /> double lowerRight_Y;<br /> }rec[10];<br /> <br /> main(){<br /> int i;<br /> int no=1;<br /> bool contain = false;<br /> int len = 0;<br /> double x,y;<br /> char temp;<br /> while(scanf("%c",&temp)){<br /> if(temp == 'r'){<br /> scanf("%lf %lf %lf %lf",&rec[len].upperLeft_X,&rec[len].upperLeft_Y,<br /> &rec[len].lowerRight_X,&rec[len].lowerRight_Y);<br /> len++;<br /> }<br /> else if(temp == '*')<br /> break; <br /> }<br /> while(scanf("%lf %lf",&x,&y)){<br /> if(x == 9999.9 && y == 9999.9)<br /> break;<br /> for(i=0;i<len;i++){ if(x > rec[i].upperLeft_X && x < rec[i].lowerRight_X && y < rec[i].upperLeft_Y && y > rec[i].lowerRight_Y){<br /> printf("Point %d is contained in figure %d\n",no,i+1);<br /> contain = true; <br /> }<br /> }<br /> if(contain == false)<br /> printf("Point %d is not contained in any figure\n",no);<br /> no++;<br /> contain = false; <br /> } <br /> }<br />
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment