CCC test prep
Author |
Message |
uknowhoiam
|
Posted: Mon Feb 23, 2009 6:28 pm Post subject: CCC test prep |
|
|
heres a question that i dont understand
Those tiny music machines that play your digital music are really computers that keep track of and
play music files. The CCC music player (C3MP) is currently in development and will be hitting
the stores soon! In this problem, you have to simulate a C3MP.
The C3MP music player will hold 5 songs in memory, whose titles will always be ?A?, ?B?, ?C?,
?D? and ?E?. The C3MP also keeps track of a playlist, which is an ordering of all the songs. The
C3MP has 4 buttons that the user will press to rearrange the playlist and play the songs.
Initially, the C3MP playist is ?A, B, C, D, E?. The 4 control buttons do the following:
_ Button 1: move the first song of the playlist to the end of the playlist.
For example: ?A, B, C, D, E? will change to ?B, C, D, E, A?.
_ Button 2: move the last song of the playlist to the start of the playlist.
For example, ?A, B, C, D, E? will change to ?E, A, B, C, D?.
_ Button 3: swap the first two songs of the playlist.
For example, ?A, B, C, D, E? will change to ?B, A, C, D, E?.
_ Button 4: stop rearranging songs and output the playlist.
You need to write a program to simulate a CCC music player. Your program should repeatedly ask
for two positive integers b and n. Here b represents the button number that the user wants to press,
1 < b < 4, and n represents the number of times that the user wants to press button b. You can
assume that n always satisfies 1 < n < 10.
The input will always finish with the pair of inputs (b = 4, n = 1) when this happens, you should
print the order of songs in the current playlist and your program should end. You can assume that
the user will only ever press button 4 once.
Sample session (user input in italics) Explanation
(initial playlist is ?A, B, C, D, E?)
Button number: 2
Number of presses: 1 (b = 2, n = 1 so ?A, B, C, D, E? changed to ?E, A, B, C, D?)
Button number: 3
Number of presses: 1 (b = 3, n = 1, so ?E, A, B, C, D? changed to ?A, E, B, C, D?)
Button number: 2
Number of presses: 3 (b = 2, n = 3, so ?A, E, B, C, D? changed to ?B, C, D, A, E?)
Button number: 4
Number of presses: 1 (b = 4, n = 1) When this happens, you should output the playlist.
Output for Sample Input Session
B C D A E
5
i need to know how to change the playlist...i cant just type in a put command, cuz that wont help...can someone help me |
|
|
|
|
|
Sponsor Sponsor
|
|
|
saltpro15
|
Posted: Mon Feb 23, 2009 6:45 pm Post subject: RE:CCC test prep |
|
|
hmm, I still have the code from this one, it's on my school computer though i'll see what i can do |
|
|
|
|
|
A.J
|
Posted: Mon Feb 23, 2009 7:05 pm Post subject: Re: CCC test prep |
|
|
uknowhoiam wrote:
i need to know how to change the playlist...i cant just type in a put command, cuz that wont help...can someone help me
They key here is to know how to manipulate strings (you can store the songs as one string)...moving a song to the end of the list is like moving the first letter of the string to the end of the string, etc... |
|
|
|
|
|
Insectoid
|
Posted: Mon Feb 23, 2009 8:19 pm Post subject: RE:CCC test prep |
|
|
To move the first character in the string to the last, I would do something like:
playlist := playlist (2..*)+playlist (1)
playlist (2..*) will take the from 2nd character of playlist to the last, while playlist (1) takes the first character. To reverse that,
playlist := playlist (*)+playlist (1..*-1)
I dunno if * works without a range, so you may have to do
playlist (length(playlist))
or whatever it would be in syntactical correctness. |
|
|
|
|
|
|
|