[ACM ] 476 runtime error

看板C_and_CPP (C/C++)作者 (丁丁)時間16年前 (2009/04/07 22:06), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/2 (看更多)
在下寫的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)

04/07 22:21, , 1F
data[6][1000] 只能放 6 個矩形喔
04/07 22:21, 1F
文章代碼(AID): #19srttPw (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #19srttPw (C_and_CPP)