|
|
вернуться в форумplease tell me why i have acces violation on test #8? Послано Husan 24 янв 2007 15:47 #include<iostream.h> #include<fstream.h> int main() { long teach[25005],stud[200005]; long i,j,kol=0,k,l,r,n,m; cin>>n; for(i=1;i<=n;i++)cin>>teach[i]; cin>>m; for(i=1;i<=m;i++) { cin>>stud[i]; l=1;r=n; for(j=1;j<=m;j++) { if(stud[i]<teach[1])break;else { k=(l+r)/2; if(stud[i]>teach[k])l=k+1;else if(stud[i]<teach[k])r=k-1;else {kol++;break;} } } }cout<<kol; return 0; } Re: please tell me why i have acces violation on test #8? M <=1000000, but for(j=1;j<=m;j++) { if(stud[i]<teach[1])break;else { k=(l+r)/2; if(stud[i]>teach[k])l=k+1;else if(stud[i]<teach[k])r=k-1;else {kol++;break;} } } It's not correct You should not to store student years Just read next student year and find it with binary search in teach[] |
|
|