UVa 476 Points in Figures: Rectangles
渣渣題三號
判斷點是否在矩形內。在頭腦不清的凌晨三點,犯了一些低級錯誤,還好很快就AC了。
我最近的休閒娛樂就是寫渣渣題....
判斷點是否在矩形內。在頭腦不清的凌晨三點,犯了一些低級錯誤,還好很快就AC了。
我最近的休閒娛樂就是寫渣渣題....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cmath> | |
using namespace std; | |
enum {MAX_REC = 10, X1 = 0, Y1 = 1, X2 = 2, Y2 = 3}; | |
int main() | |
{ | |
int numRec = 0; | |
double rec[MAX_REC][4]; | |
char c; | |
while (scanf(" %c", &c)) | |
{ | |
if (c == '*') | |
break; | |
scanf("%lf %lf %lf %lf", | |
&rec[numRec][X1], &rec[numRec][Y1], &rec[numRec][X2], &rec[numRec][Y2]); | |
numRec++; | |
} | |
double x, y; | |
int numPoint = 1; | |
int outRec; | |
while (scanf(" %lf %lf", &x, &y)) | |
{ | |
if (x == 9999.9 && y == 9999.9) | |
break; | |
outRec = 1; | |
for (int i = 0; i < numRec; ++i) | |
{ | |
if (x > rec[i][X1] && y < rec[i][Y1] && | |
x < rec[i][X2] && y > rec[i][Y2]) | |
{ | |
printf("Point %d is contained in figure %d\n", numPoint, i + 1); | |
outRec = 0; | |
} | |
} | |
if (outRec) | |
printf("Point %d is not contained in any figure\n", numPoint); | |
numPoint++; | |
} | |
return 0; | |
} | |
我想請教為何 while(scanf(" %c",&c)){ 中的 %c 前必需要有空格?
回覆刪除............
回覆刪除