C Lab 3 – Transpose
Due Saturday 10 April 11:59pm
The conventional western musical scale is based on 12 tones:
A A# B C C# D D# E F F# G G#
The sequence repeats indefinitely – the next note higher than G# is also called A.
Each step from one note to another in this sequence is called a half-step. The # symbol is called a “sharp” and actually means “raised a half step”. Hence “A#” is “A raised a half-step”. There is a similar symbol `b” meaning “lowered a half-step” .
Given that meaning for # and b, it is possible for notes to actually be referred to by more than one name. A# and Bb refer to the same note. B# means the same as C. Fb means the same as E.
A common task for musical arrangers is to transpose a work of music – to raise or lower the entire work by some number of half-steps in order to fit better into the range of a particular singer or musical instrument. A proper transposition will preserve the number of half-steps between any two successive notes in the work.
Input
Input consists of one or more input sets.
An input set consists of a line containing a sequence of 0 or more notes with sharp and flat marks, each note separated from the others by one or more blanks. This is followed by a line containing a single integer indicating the number of half-steps to transpose the piece (positive numbers indicating the notes should be transposed up, negative indicating it should be transposed down).
The end of input is signaled by a line consisting of the string “***”.
Output
For each input set, you should print one line containing the sequence of transposed notes, each represented as in the list of 12 given at the start of this problem. Notes should be printed with a single blank space separating them.
Sample Input
C# E Db G#
1
D E# D A
-1
***
Sample Output
D F D A
C# E C# G#
Logistics
Origin of Problem
3919 – First Composed, Then Transposed
ACM-ICPC Live Archive: North America – Mid Atlantic – 2007/2008
Submission Guidelines
Use the ACM-ICPC Live Archive – Submit-o-matic 6.0. Please forward the ACM results.
Also please submit your program using the turnin script . If (and only if) you have a problem with turnin, email me your program.
Points awarded
7 points – your code runs in 0.001 CPU time or less (or is the fastest in the class)
5 points – your code runs in 0.004 CPU time or less
4 points – your code runs on the Submit-o-matic 6.0 server and is clean and well organized.
2 points – your code runs and produces correct results locally but does not run on Submit-o-matic 6.0 server.
0 points – all other conditions.
Comments on Code that Submit-O-Matic didn’t like
The notes file consisted of
Adams
Your code produces the following incorrect output on that input
D F D A
C# E C# C#
D#
C# F G# F C#
Bain
Your program produces double new lines but otherwise looks correct.
Connelly
Your program is printing debug statements (i.e., “currnote: C after shift: D”)
Cordova
Your program just outputs debug lines.
Jones
Program does not compile. You use C++ style comments, which should be changed to /* */
Wichert
Program generates seg fault:
D F D A
G# G# G# G# G# G# G# G# E G# G# G# G# G# G# G# C# G# G# G# G# G# G# G# G#
A E G E C
Segmentation fault