|
|
back to boardCrash (access violation) test 6. HELP Posted by Tom 20 May 2011 02:46 here s my code, it worked for every test i ve done. no ideas why it s not getting acc Help pls #include <iostream> using namespace std; int Pop(int a,char* tablica){ tablica[a-1] = 0; tablica[a-2]=0; return a-2; } void Usun(char* tablica, int x){ int i, j; if(x>1){ for(i=0;i<x;i++){ if(tablica[i]==tablica[i+1]){ if (i + 2 < x){ tablica[i]=tablica[i+2]; if (i + 3 < x){ tablica[i+1]=tablica[i+3]; } for(j=i+2;j<x-2;j++){ tablica[j]=tablica[j+2]; } } x=Pop(x, tablica); } } if (1 < x){ for(i=0;i<x;i++){ if(tablica[i]==tablica[i+1]) Usun(tablica,x); } } } } int main(){
char tablica[20000]; int x; gets (tablica); x = strlen(tablica); Usun(tablica, x); cout << tablica; delete [] tablica;
} Edited by author 20.05.2011 03:16 Re: Crash (access violation) test 6. HELP Posted by AterLux 20 May 2011 14:26 Access violation in most cases mean read-write out of range: so, you have to look on your arrays sizes first For example, input could be up to 200000 chars, your array only 20000 Re: Crash (access violation) test 6- fixed. TLE6 now. Help again Posted by Tom 20 May 2011 16:52 jizz man. i havent noticed it was 200k, all the time i thought it s 20k. that s it, no more access violation. but now TLE - 6 1.046sec. how can i make it faster ? ed: deleted all if`s and using function USUN with pointer. it should be little faster that way, but still too slow Edited by author 20.05.2011 16:55 Re: Crash (access violation) test 6- fixed. TLE6 now. Help again Posted by AterLux 20 May 2011 19:08 You need not to delete (shift all tail of array) on every time you meet pair. Actually, you can build new array with only good symbols with one array-pass. Edited by author 20.05.2011 19:10 |
|
|