|
|
вернуться в форумCrash (access violation) №5 Even n=1000 works well 1 1 1 ... 1 1 1 2 2 2 ... 2 2 2 3 3 3 ... 3 3 3 4 4 4 ... 4 4 4 5 5 5 ... 5 5 6 (there are 200 digits of 1,2,3,4, but there's 199 digit 5 and one digit 6) The output is 200 1 200 2 200 3 200 4 199 5 1 6 Why crash?Test,please... Here's the code : #include <iostream> using namespace std; int main() { int n,i,sum=0,k=0; cin>>n; int *a=new int [n]; for(i=0;i<n;i++) cin>>a[i]; int *b=new int [n]; for(i=0;i<n;i++) { if(a[i]==a[i+1]) { sum++; continue; } else { b[k]=sum+1; b[k+1]=a[i]; k+=2; sum=0; } } for(i=0;i<k;i++) cout<<b[i]<<" "; return 0; } Edited by author 13.11.2010 12:56 Re: Crash (access violation) №5 Послано vahan 13 ноя 2010 13:07 in this problem size b isn't always <= n, for example in test 1 1 your b size = 2 take the greater size for b Edited by author 13.11.2010 15:41 Edited by author 13.11.2010 15:41 Re: Crash (access violation) №5 Got AC,ապրես |
|
|