Daily test "load_large"

My program passed all the tests except load_large_file, and the daily test feedback a timeout. Is there any direction to fix it? I can run it fine locally and I’m sure my program can load a large word list. I used scanf in the implementation and didn’t take into account words of length not k, which seems to be fine.
Thanks!

Think about possible edge cases.
The test might have something to do with loading some file.
By deduction from the name, something about the file might be large.

You could write more unit tests and test if your loading works correctly. Generate a few files for tests of edge cases.

Should I consider the word larger than a real English/German word?

We do not restrict our specification to English/German words.
Therefore, longer words could occur.

1 Like

Ok, thanks a lot, I will try it again!

You might generate a file of 1000000 lines, each 10 chars long. My implementation can load this in about 3 seconds, consuming about 2.5 GB of RAM. How long does yours take?

Almost 4 seconds, seems good. And I find that if the k is not the same as the only word in the file, my program will get stuck, it’s a problem?

You may assume that you only encounter words of length exactly k.

1 Like

You might also want to ensure that you are able to handle arbitrarily long input strings, in generateDict as well as in guess. In particular, 127 chars seems too low.

1 Like

The number 127 is exactly what I used :joy:
Thanks a lot.

I know, that’s why I used it here :upside_down_face: :mage:

1 Like

If I malloc a dynamic memory block, how can I ensure the max size of the scanf string? (The editor asked me to do that.)

man 3 scanf will tell you this. Read it fully, it may contain useful information.

To answer your concrete question, you add a maximum field width specifier. For example, %127s will read 127 chars, add a '\0', so this will fit into 128 bytes. As far as I can tell, you’re doing this already…

Ohhh…I have done that, but for loading a word larger than 127, the restriction of 127 is not good, so we have only a max size of 127.