Advertisement
nocturnalmk

Untitled

Nov 24th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. In an ancient land, the beautiful princess Eve had many suitors. She decided on
  2. the following procedure to determine which suitor she would marry. First, all of the
  3. suitors would be lined up one after the other and assigned numbers. The first suitor
  4. would be number 1, the second number 2, and so on up to the last suitor, number
  5. n. Starting at the first suitor, she would then count three suitors down the line
  6. (because of the three letters in her name) and the third suitor would be eliminated
  7. from winning her hand and removed from the line. Eve would then continue, counting
  8. three more suitors, and eliminating every third suitor. When she reached the end
  9. of the line, she would reverse direction and work her way back to the beginning.
  10. Similarly, on reaching the first person in line, she would reverse direction and make
  11. her way to the end of the line. For example, if there were five suitors, then the
  12. elimination process would proceed as follows:
  13. 12345 Initial list of suitors; start counting from 1.
  14. 1245 Suitor 3 eliminated; continue counting from 4 and bounce from end
  15. back to
  16. Suitor 4 eliminated; continue counting back from 2 and bounce from
  17. front back to 2.
  18. 15
  19. Suitor 2 eliminated; continue counting forward from 5.
  20. 1
  21. Suitor 5 eliminated; 1 is the lucky winner.
  22. Write a program that uses an ArrayList or Vector to determine which position you
  23. should stand in to marry the princess if there are n suitors. Your program should
  24. use the ListIterator interface to traverse the list of suitors and remove a suitor. Be
  25. careful that your iterator references the proper object upon reversing direction at
  26. the beginning or end of the list. The suitor at the beginning or end of the list should
  27. only be counted once when the princess reverses the count.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement