-
UID:52598
-
- 注册时间2008-07-17
- 最后登录2017-09-14
- 在线时间21小时
-
- 发帖28
- 搜Ta的帖子
- 精华0
- 金钱290
- 威望30
- 贡献值0
- 好评度29
-
访问TA的空间加好友用道具
|
我程序改了一下,现在出现如下问题: 代码如下: #include<stdio.h> #include<iostream.h> #include<math.h> struct data{ int n; int num; int ax[350]; int ay[350]; }shu[3057],shuf[3057]; int x9=0,y9=0; int jj=0; int jisu=0; int pen=0; class fsettle { public: fsettle() { cout<<"qq"<<endl; } //~fsettle(); void copyy(); void deal(); }; int main() { fsettle a; a.copyy(); a.deal(); return 1; } void fsettle::copyy() { FILE *p1; int num1,x,y; if((p1=fopen("jiaxing_pline.txt","r"))!=NULL) { while(fscanf(p1,"%d\n",&num1)==1) { shu[jj].n=jj; shu[jj].num=num1; for(int i=0;i<num1;i++) { fscanf(p1,"%d %d\n",&x,&y); shu[jj].ax =x; shu[jj].ay=y; } jj++; } } fclose(p1); }
bool qiujiao(float x1,float x2,float x3,float x4,float y1,float y2,float y3,float y4) { float d; d=((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1)); if(fabs(d)>1e-002) { x9=(int)(((x2-x1)*(x4-x3)*(y3-y1)+(y2-y1)*(x4-x3)*x1-(y4-y3)*(x2-x1)*x3)/d); y9=(int)(((y2-y1)*(y4-y3)*(x1-x3)-(x2-x1)*(y4-y3)*y1+(x4-x3)*(y2-y1)*y3)/d); if((x9-x1)*(x9-x2)<=0&&(x9-x3)*(x9-x4)<=0&&(y9-y1)*(y9-y2)<=0&&(y9-y3)*(y9-y4)<=0) return true; else return false; } else return false; }
void fsettle::deal() { FILE *fpp; ////fpp=fopen("cun.txt","w"); ////fclose(fpp); float x1,x2,x3,x4; float y1,y2,y3,y4; if((fpp=fopen("cun.txt","w"))==NULL) return; int j=0;
for(int b2=0;b2<jj;b2++)//b2=1210 { int k=0; int pan=0; int u=0; for(int b3=0;b3<shu[b2].num-1;b3++) { x1=(float)shu[b2].ax[b3]; y1=(float)shu[b2].ay[b3]; x2=(float)shu[b2].ax[b3+1]; y2=(float)shu[b2].ay[b3+1]; for(int b=0;b<jj;b++) { for(int b1=0;b1<shu[bb].num-1;b1++)//两个b的地方其实是一个b,要不然就不能显示了。 { //shu[1].num=9;shu[3].num=5; x3=(float)shu[bb].ax[b1]; y3=(float)shu[bb].ay[b1]; x4=(float)shu[bb].ax[b1+1]; y4=(float)shu[bb].ay[b1+1]; bool cross=qiujiao(x1,x2,x3,x4,y1,y2,y3,y4); if(shu[b2].n!=shu[bb].n&&cross) { int pand=0; pan++; shuf[j].n=j; shuf[j].num=b3+1-k; ////fpp=fopen("cun.txt","a"); u=b3+1; if(b3==0) { pan=0; pand=1; } if(shuf[j].num!=0&&pand==0) { if(pan>1) { fprintf(fpp,"%d\n",shuf[j].num+2); fprintf(fpp,"%d %d\n",shuf[j].ax[0],shuf[j].ay[0]);
} else fprintf(fpp,"%d\n",shuf[j].num+1); for(int b4=0;b4<shuf[j].num;b4++) { shuf[j].ax[b4]=shu[b2].ax[b4+k]; shuf[j].ay[b4]=shu[b2].ay[b4+k]; fprintf(fpp,"%d %d\n",shuf[j].ax[b4],shuf[j].ay[b4]); } shuf[j+1].ax[0]=x9; shuf[j+1].ay[0]=y9; fprintf(fpp,"%d %d\n",x9,y9); j++; k=b3+1; } } } } } if(pan==0) { shuf[j].n=j; shuf[j].num=shu[b2].num; fprintf(fpp,"%d\n",shuf[j].num); for(int b4=0;b4<shuf[j].num;b4++) { shuf[j].ax[b4]=shu[b2].ax[b4]; shuf[j].ay[b4]=shu[b2].ay[b4]; fprintf(fpp,"%d %d\n",shuf[j].ax[b4],shuf[j].ay[b4]); } j++; } else { shuf[j].n=j; shuf[j].num=shu[b2].num-u; fprintf(fpp,"%d\n",shuf[j].num+1);
fprintf(fpp,"%d %d\n",shuf[j].ax[0],shuf[j].ay[0]); for(int b4=0;b4<shuf[j].num;b4++) { shuf[j].ax[b4]=shu[b2].ax[b4+u]; shuf[j].ay[b4]=shu[b2].ay[b4+u]; fprintf(fpp,"%d %d\n",shuf[j].ax[b4],shuf[j].ay[b4]); } j++; } } fclose(fpp); cout<<"success!"<<endl; }
jiaxing_pline.txt文件内容格式如下: 3 12072859 3079266 12072637 3079954 12072520 3080248 9 12071059 3079554 12071226 3079247 12071325 3079046 12071477 3078709 12071553 3078539 12071564 3078502 12071564 3078460 12071540 3078260 12071488 3077870 11 12071325 3079046 12071465 3079066 12071553 3079086 12071588 3079096 12071826 3079173 12072013 3079239 12072264 3079311 12072579 3079376 12072807 3079416 12073075 3079461 12073268 3079512 现在出现的错误是: Program received signal SIGSEGV, Segmentation fault. 0x08048c81 in fsettle::deal (this=0xbffeb617) at fsettle1.cpp:110 110 y4=(float)shu.ay[b1+1]; (gdb) bt #0 0x08048c81 in fsettle::deal (this=0xbffeb617) at fsettle1.cpp:110 #1 0x08049538 in main () at fsettle1.cpp:34 (gdb) [ 此贴被泡茉蓝茶在2009-02-16 14:02重新编辑 ]
|