this does not account for the nul terminator (1 byte is missing)
char*res=(char*)malloc(strlen(od));
same remark
if(*s=='\0'){
return"";
the tests expect the returned string to be free()-able. "" is a string literal that cannot be freed
if(*od=='\0'){
char*cp=NULL;
strcpy(cp,s);
you are attempting to write at the null pointer here. this will crash. you have to allocate memory for `cp`.
your code passes once all these are fixed.
I'd try to reproduce it locally, at the very least you should be able to find out what inputs it happens for by printing (and flushing to ensure it isn't stuck in a buffer) and probably throw ASan or similar at it to see if it notices anything. Of course, it might be something unexpected going on in the test code that you can't reproduce yourself - for which I suppose very carefully finding out how your function should behave is a start.
When i run your code against the tests and print out the indata, it turns out it does happen for an obviously special test case, so there's a good chance you don't need to dig any further than that.
CS: last testcase expects {"1":4,"5":1,"10":0,"25":1366087610} but should be { '1': 4, '5': 1, '10': 0, '25': 2397957838778 } as stated 9 years ago. Still applies.
Lua translation
All fixed in this fork
Done in this fork
This comment is hidden because it contains spoiler information about the solution
thanks for the thorough answer!
the tests expect the returned string to be
free()
-able.""
is a string literal that cannot be freedI'd try to reproduce it locally, at the very least you should be able to find out what inputs it happens for by printing (and flushing to ensure it isn't stuck in a buffer) and probably throw ASan or similar at it to see if it notices anything. Of course, it might be something unexpected going on in the test code that you can't reproduce yourself - for which I suppose very carefully finding out how your function should behave is a start.
When i run your code against the tests and print out the indata, it turns out it does happen for an obviously special test case, so there's a good chance you don't need to dig any further than that.
hello everyone! i'm newby in C and trying to solve this task, but failing in a random test: get SIGSEGV. what could be the reason? (code below)
Sort string1 based on the corresponding character's positioning in string2. So,
a
comes first followed byb
, thenn
, sobanana
becomesaaabnn
Approved
python new test framework
This comment is hidden because it contains spoiler information about the solution
CS: last testcase expects
{"1":4,"5":1,"10":0,"25":1366087610}
but should be{ '1': 4, '5': 1, '10': 0, '25': 2397957838778 }
as stated 9 years ago. Still applies.Also no random tests and no sample tests.
Nice!
Retired.
Loading more items...