|
|
вернуться в форумWhy does this program gets Crash Access Violation? (+), thnks in advance :) #include<iostream.h> struct line { long a, b; char c; }; line *l; int ls; void main() { int n, i, j, pos; line ll, h; cin>>n; l = new line[2*n+1]; ls = 0; for (i=0; i<n; i++) { cin>>ll.a>>ll.b>>ll.c; if (ll.b - ll.a==0) continue; //compare with last lines not overlapped for (j=0; j<ls; j++) { if (ll.a<l[j].a && ll.b>l[j].b) { --ls; h=l[ls];l[ls]=l[j];l[j]=h; --j; } else if (ll.a>l[j].a && ll.b<l[j].b) { l[ls] = l[j]; l[j].b = ll.a; l[ls].a = ll.b; ls++; } else if (l[j].a<ll.a && ll.a<l[j].b) l[j].b = ll.a; else if (l[j].a<ll.b && ll.b<l[j].b) l[j].a = ll.b; }// for (j) l[ls] = ll; ls++; }//for (i) //sort them for (i=0; i<ls-1; i++) { pos = i; for (j=i+1; j<ls; j++) if (l[j].a<l[pos].a) pos=j; if (pos!=i) { h = l[i]; l[i]=l[pos]; l[pos]=h; } } line max, prev; max.a = 0; max.b = 1; prev.a = 0; prev.b = l[0].a; j = 0; //go through the lines and get the maximum while ( j < ls ) { while ( j < ls ) { if (l[j].c=='w') prev.b = l[j].b; else { prev.b = l[j].a; break; } j++; } if (prev.b-prev.a>max.b-max.a) max = prev; if ( j < ls ) { prev.a = l[j].b; prev.b = l[j].b; } j++; } if (1000000000-l[ls-1].b>max.b-max.a) { max.b = 1000000000; max.a = l[ls-1].b; } delete[] l; cout<<max.a<<" "<<max.b<<endl; } Ask SongChao I can't understand you program. But I give you a suggestion. My friend SongChao Has Slove this problem with your method . You could ask him about it. And I think he'll give you a satisfy answer. Here or by email? :) (-) > I can't understand you program. > But I give you a suggestion. > My friend SongChao Has Slove this problem with your method . > You could ask him about it. > And I think he'll give you a satisfy answer. Re: Here or by email? :) (-) By E-mail. |
|
|