Write a program called Chomp
that takes a single argument
that is a non-empty string of nonincreasing digits starting with a non-zero
digit representing the state
of a game of Chomp. The output should be a single line containing
"LOSS" if there is no winning move from that state and "WIN" along
with the state resulting from making the winning move
if there is a winning move. The output should
be in the format given in the example below. If there is more than
one winning move then the output should reflect the one that selects
the leftmost piece among all the winning moves.
Your program must be efficient in terms of time and memory, where "efficient" is defined as "passes the large public test cases without execeeding the time or memory limits".
If the input file or command-line arguments are not as specified then your program must behave gracefully: it must not crash or go into an infinite loop.
Your program and any program
must not produce any error messages when run with
valgrind --tool=memcheck --leak-check=yes -q
.
We reserve the right to deduct points from submissions for violations of the following guidelines.
#include
d regardless of what other files have
been #include
d -- if a declaration is required by
your header files, then #include
the appropriate
header file in your header file (or write a forward declaration in
your header) rather than relying on your #include
rs
to have already #include
d those header files before
they #include
yours.
const
should be declared as const
.
-Wall
and -pedantic
options.
[jrg94@tick Chomp]$ ./Chomp 33333 WIN: 33322 [jrg94@tick Chomp]$ ./Chomp 33322 LOSS [jrg94@tick Chomp]$ ./Chomp 33321 WIN: 22221
/home/httpd/html/zoo/classes/cs223/f2017/Assignments/Chomp
. You may make any changes
to this code as you see fit.
main
)