作者bil193 (丁丁)
看板C_and_CPP
标题[ACM ] 476 runtime error
时间Tue Apr 7 22:06:46 2009
在下写的ACM Q476: Points in Figures: Rectangles
程式感觉还ok,测资也ok,可是却runtime error,一直找不到bug...
Runtime Error (RE):
程式成功编译,但发生执行期错误(非法操作记忆体、除以 0 等等问题)。
可是我并没动到记忆体之类的啊@@
在此附上问题及程式码
Q476: (
http://luckycat.kshs.kh.edu.tw/homework/q476.htm)
Code:
http://rafb.net/p/yE9cNH93.html
文字版:(怕连结失效用)
#include<stdio.h>
#include<stdlib.h>
int main()
{
double data[6][1000]={1},temp[1000]={0},point[1000][2]={0};
char ttemp[1000]={'0'};
int i=0,j,count1,count2,flag;
fgets(ttemp,1000,stdin);
while(ttemp[0]!='*') //此回圈读取*之前的资料,存到data[][]里
{
sscanf(ttemp,"%c %lf %lf %lf
%lf",&temp[4],&temp[0],&temp[1],&temp[2],&temp[3]);
for(j=0;j<4;j++)
data[i][j]=temp[j];
i++;
//printf("%d\n",++i);
fgets(ttemp,1000,stdin);
}
count1=i;
i=0;
fgets(ttemp,1000,stdin);
sscanf(ttemp,"%lf %lf",&temp[0],&temp[1]);
while( !(temp[0]==9999.9 && temp[1]==9999.9)) //此回圈读取9999.9前的资料,
存到point[][]里
{
for(j=0;j<2;j++)
point[i][j]=temp[j];
i++;
fgets(ttemp,1000,stdin);
sscanf(ttemp,"%lf %lf",&temp[0],&temp[1]);
}
count2=i;
for(i=0;i<count2;i++) //判断并印出结果
{
flag=0;
for(j=0;j<count1;j++)
{
if(point[i][0]>data[j][0] && point[i][0]<data[j][2] &&
point[i][1]<data[j][1] && point[i][1]>data[j][3])
{
printf("Point %d is contained in figure %d\n",i+1,j+1);
flag=1;
}
}
if(!flag)
printf("Point %d is not contained in any figure\n",i+1);
}
system("pause");
return 0;
}
各位先进多多指教,小弟刚开始摸ACM...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.98.95
※ 编辑: bil193 来自: 140.113.98.95 (04/07 22:08)
1F:推 ledia:data[6][1000] 只能放 6 个矩形喔 04/07 22:21