|
|
back to boardWhy i have crash(access violation) Posted by Husan 17 Mar 2007 17:10 #include<iostream.h> #include<math.h> int st[22],n1,n; long a[22]; int prov() { int i,sum1=0,sum2=0,pr[6]={0}; for(i=1;i<=n1;i++){sum1+=a[st[i]];pr[st[i]]=1;} for(i=1;i<=n;i++) if(pr[i]!=1)sum2+=a[i]; return abs(sum1-sum2); } int main() { int i,min=10000; cin>>n; for(i=1;i<=n;i++)cin>>a[i]; n1=1;st[n1]=1; while(st[1]<n) { if(st[n1]>=n) { n1--; st[n1]++; if(min>prov())min=prov(); continue; } if(min>prov())min=prov(); n1++; st[n1]=st[n1-1]+1;
} n1=1; st[n1]=n;
if(min>prov())min=prov(); cout<<min; return 0; } |
|
|