Please, someone who had had solved this problem, see my code and tell me why do i get "Invalid memory reference (memory limit exceeded)" on every test... I used pointers... Maybe I made mistake there... But it works like clock on my PC..
z-hundred
Did you consider negative numbers ?
I need help...
http://z-trening.com/submit.php?submit=7100340193&subm_code=1
http://z-trening.com/submit.php?submit=7100340193&subm_code=1
maybe you forgot to decrease i?
But you will still get TLE, because time complexity of your solution is O( N * N * length of number), so in worst case that is 2000 * 2000 * 1000 operations, and that is just too many.
But if you would use quick sort, or some other NlogN complexity sort, you would have time complexity O( N*logN*length of number), which is in worst case 2000 * 20 * 1000, which is fine...
while(strcmp(p[i],p[i-1])<0 && i>0){
strcpy(d,p[i]);
strcpy(p[i],p[i-1]);
strcpy(p[i-1],d);
i--;
}
But you will still get TLE, because time complexity of your solution is O( N * N * length of number), so in worst case that is 2000 * 2000 * 1000 operations, and that is just too many.
But if you would use quick sort, or some other NlogN complexity sort, you would have time complexity O( N*logN*length of number), which is in worst case 2000 * 20 * 1000, which is fine...
Also don't print all numbers:
//system("pause");
for(i=0;i<cnt;i++){
printf("%s\n",p[i]);
}