Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Wasn't the point of the problem to add floats and integers?

  • Custom User Avatar

    I thought pow only accepted doubles? I see it works, I am just not quite sure why. Wouldn't there be a danger of pow() returning a double just below the proper integer and then by casting it to an int, it would round down it in the result?

  • Custom User Avatar

    but the array is an integer??

  • Custom User Avatar

    Really neat way to iterate over the digits in reverse order using modulo and division by 10! Impressed!

  • Default User Avatar

    After testing ang googling, I must admit that you are right, thank you for pointing that out.

  • Default User Avatar

    Not correct, since floor does return the same value if the input is a round number. Just googled it. Just writing it down here for newbies like me, who read your comment and wonder if thats true.

  • Custom User Avatar

    I think if the result has all 26 letters then you'd better calloc 27 (not 26) to make room for the \0, otherwise ...

  • Default User Avatar

    you too!

  • Default User Avatar

    IMHO, there is a problem for n=10, n=100, n=1000 (...) since in those cases floor(log10(n))+1 won't return the right number of digits.

  • Custom User Avatar

    umm, maybe no? because they initialized the array as integer.

  • Custom User Avatar

    I am very impressed - a very clever solution! My solution took me a while and I wrote 60 lines in total (adding comments explaining everything). Your solution is a lot better, but mine is more readable, in my opinion.

  • Custom User Avatar

    Almost identical to mine. As well as the OB1 problem (the final string might be of 27 bytes including the null terminator), there's a second issue: overflow in letters.

    while(*s1) letters[*s1++] = 1;
    

    won't suffer from this.

  • Custom User Avatar

    @caelumable, temp is merely a pointer. It points into same chunk of calloced memory that final points at.

    That memory will be freed in the test code.

    EDIT: My mistake, the test code doesn't free the returned memory at all. I guess the author wrote code in this way to allow solutions this return references to static variables.

  • Default User Avatar

    eum....may I ask when dose the temp be destroyed? and why ? the temp didn't declear in the domain of the for loop, why it destroyed after the for loop?