|
How do I parse the command-line inputs? The easiest solution is something like
As usual, our emphasis in 226 is not on bulletproof input validation.int main(int argc, char *argv[]) { int K, M; if (argc != 3) exit(EXIT_FAILURE); K = atoi(argv[1]); M = atoi(argv[2]);
What is the alphabet size? The inputs consist of ASCII text, not just lowercase letters and whitespace. Do not assume it is 26 or 96 or some other arbitrary number.
My random process dead ends because it generates a match for for the final k characters of the input file, but this string does not appear anywhere else in the input. That's OK. If you prefer, you can repeatedly restart your code from the beginning until you get the right number of characters.
Should my program generate a different output each time I run it? Yes. You can do this by setting the random number generator seed according to the system clock. Include <stdlib.h> and <time.h> and the following line (once only) at the beginning of the main routine:
Note that you might want to disable this feature when debugging.unsigned int seed = time(NULL); srand(seed);
Do I need to print the distinct keys or the frequency lists in lexicographic order like in the reference solutions? No, you are free to print them out in whatever order is most convenient. However, if you want to compare your solutions with our reference solutions, the lexicographic ordering might make things easier.
|
Input and output. Here are a number of sample input files. They are the same ones from last week.
Our program ignores the last character read in because this is always a newline character in our sample files. This helps prevent the dead-ending on some small test files.
Reference solutions. For reference, we provide executable code for our solution in Windows, Solaris, and OS X. We encourage you to develop a more efficient program! It is certainly possible that you may be able to beat our solution, and it is also possible that you will get most/all of the credit even if your method is not quite as efficient.
|
We will compile your program with "gcc *.c" so you are free to organize your program as you see fit. As usual, we encourage and reward sound design principles.
Here is a template readme.txt file. It should contain the following information:
Unix users may find the shell script timeit.csh useful for computing a table of CPU times.
|