/* 1997 East-Central ACM regional programming contest Held on November 8, 1997 Coconuts, Revisited -- Problem 3 Sample solution by Ed Karrels, Ed@tool.com November 1997 */ #include /* return 1 if this number of coconuts can be divided up properly between this number of people */ int SplitCoco(long n_coco, long n_people) { long i; for (i=0; i 1; n_people--) { if (SplitCoco(n_coco, n_people)) { printf("%ld coconuts, %ld people and 1 monkey\n", n_coco, n_people); goto found; /* OK, so yea, I put a 'goto' in my code :-) it was quick and it works. I don't do it often, I swear. */ } } /* if no number of people greater than 1 works, there is no solution */ printf("%ld coconuts, no solution\n", n_coco); found: } return 0; }