Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
CS 241 Lab #5: Striking sequences via DCLLs
[go: Go Back, main page]

Lab #5: Striking sequences via DCLLs

Assigned: Mon 8 Mar 04
Due: Mon 15 Mar 04


The problem statement

As mentioned in class, this problem is much shorter and less "pithy" than the last one, with nowhere near the motivational background. In fact, it is taken in large part from a high school programming contest of the same name (described in class and reproduced below), with two changes:
  1. we will allow negative numbers in the sequence (heck, let's throw in zero while we're at it!);

  2. we will specifically require that the solution be cast in terms of doubly-circularly-linked lists (or DCLLs for short).

OK, here's the original contest problem text:

Say we have a sequence of positive numbers: we can strike off the first one in the sequence, call it k, and then strike off every kth number following. This will give us a new sequence, so that we can repeat the process. Eventually, we will run out of numbers and be doneÑtypically this happens when we reach a 1 at the front. Here is an example:
Write a program which will read in a sequence of numbers (possibly on several lines), terminated by a zero (which is not part of the sequence). It should then print out the original sequence and each of the ÒstrickenÓ versions, not with actual slashes through the numbers, of course, but with only the remaining values showing. For example:
		2 3 4 2 3 1 2 5 2 3 4 1 3 2

		3 2 1 5 3 1 2

		2 1 3 1

		1 1

For our purposes, as noted above, we will also allow negative and zero values in the sequence, with the following interpretations: