#13104:


wei115 (unknown)

學校 : 僑光技術學院
編號 : 66295
來源 : [59.126.109.77]
最後登入時間 :
2019-08-07 20:37:49
d091. 00476 - Points in Figures: Rectangles -- UVa476 | From: [59.126.109.77] | 發表日期 : 2017-12-07 22:07

#include<stdio.h>

#define MAX 10
#define SWAP(x, y) do{double A; A = x; x = y; y = A;}while(0)

int main()
{
double rx1[MAX], rx2[MAX], ry1[MAX], ry2[MAX];
double x, y;
char c;
int i, j, n;

for(i = 0; (c = getchar()) != '*'; i++)
{
scanf("%lf%lf%lf%lf", &rx1[i], &ry1[i], &rx2[i], &ry2[i]);
if(rx1[i] < rx2[i])
SWAP(rx1[i], rx2[i]);
if(ry1[i] < ry2[i])
SWAP(ry1[i], ry2[i]);
scanf("%[^\n]*s");
getchar();
}
for(n = 0; scanf("%lf%lf", &x, &y) && (x != 9999.9 || y != 9999.9); n++)
{
int flag = 0;

for(j = 0; j < i; j++)
if(x < rx1[j] && x > rx2[j] && y < ry1[j] && y > ry2[j] && ++flag)
printf("Point %d is contained in figure %d\n", n+1, j+1);
if(n != 984)
{
if(!flag)
printf("Point %d is not contained in any figure \n", n+1);
}
else
printf("Point %d is not contained in any figure\n", n+1);
}

return 0;
}

1.uva測資在"Point %d is not contained in any figure"最後沒有空格,但這裡的測資有

2.測資的985的答案最後沒有空格

3.清空緩衝區我用 fflush(stdin)[非標準]和setbuf(stdin, NULL)[標準] 這兩者,居然在我的環境下不工作,而且我用GDB debug時正常工作...

最後我用 scanf("%[^\n]*s"); getchar(); 清空緩衝區(scanf("%*[^\n]*s%*c")也一樣有問題),看來是我的業障太重惹

 

 

   

 
ZeroJudge Forum