Transposition
Time limit1sMemory limit128 MB
Transpose a list of note names by a given number of semitones, then print each note using the 12 canonical sharp names.
- Level
Easy3 of 10
- Topics
- String, Hash map, Implementation, Math
- Solved
- No attempts yet
Problem
The Western musical scale consists of 12 tones:
A A# B C C# D D# E F F# G G#
These 12 tones repeat infinitely: the tone immediately above G# is A again.
Any two adjacent tones are a semitone apart. The symbol # (sharp) raises a tone by a semitone, so A# is A raised by one semitone. The symbol b (flat) lowers a tone by a semitone.
Using # and b, the same tone can be written with different names. For example, A# and Bb are the same tone, B# is the same as C, and Fb is the same as E.
Transposition means shifting every tone of a piece up or down by the same number of semitones. After transposition, the number of semitones between adjacent tones (the intervals) must stay the same as before.
Given a piece, write a program that outputs its transposition.
Input
The input consists of several test cases.
Each test case is given on two lines. The first line lists the tones of the piece in order, with one or more spaces separating consecutive tones. The second line contains an integer: the number of semitones to transpose by. A positive value shifts up by that many semitones, and a negative value shifts down.
The last line of the input is ***, which marks the end of the input.
Output
For each test case, print the transposed piece on its own line. Every tone you print must be one of the 12 tones listed in the statement (A A# B C C# D D# E F F# G G#).