Veronica attends a music academy. She was given a music sheet of a composition with only notes (without annotations), and needs to recognise the scale used. In this problem, we will limit ourselves to only the two most frequently used (and usually taught in schools first) scales: -minor and -major. This doesn't make them simpler or more basic than other minor and major scales – all minor scales are mutually equivalent save for translation, and so are major scales.
Still, out of the tones of an octave used in modern music, -minor and -major scales do use the tones with shortest names: -minor is defined as an ordered septuple , and -major as .
Notice that the sets of tones of these two scales are equal. What's the difference? The catch is that not only the set of tones, but also their usage, determines a scale. Specifically, the tonic (the first tone of a scale), subdominant (the fourth tone) and dominant (the fifth tone) are the primary candidates for accented tones in a composition. In -minor, these are , , and , and in -major, they are , , and . We will name these tones main tones.
Aren't the scales still equivalent save for translation? They are not: for example, the third tone of -minor is three half-tones higher than the tonic , while the third tone of -major is four halftones higher than the tonic . The difference, therefore, lies in the intervals. This makes minor scales "sad" and major scales "happy".
Write a program to decide if a composition is more likely written in -minor or -major by counting whether there are more main tones of -minor or of -major among the accented tones (the first tones in each measure). If there is an equal number of main tones, determine the scale based on the last tone (which is guaranteed to be either for -minor or for -major in any such test case).
For example, examine the well-known melody "Frère Jacques":
The character |
separates measures, so the accented tones are, in order: . Ten of them are main tones of -major, while six are main tones of -minor. Therefore, our best estimate is that the song was written in
-major.
Input Specification
The first and only line of input contains a sequence of at least , and at most , characters from the
set A
, B
, C
, D
, E
, F
, G
, |
. This is a simplified notation for a composition, where
the character |
separates measures. The characters |
will never appear adjacent to one another, at
the beginning, or at the end of the sequence.
Output Specification
The first and only line of output must contain the text C-dur
(for -major) or A-mol
(for -minor).
Sample Input 1
AEB|C
Sample Output 1
C-dur
Sample Input 2
CD|EC|CD|EC|EF|G|EF|G|GAGF|EC|GAGF|EC|CG|C|CG|C
Sample Output 2
C-dur
Comments
Guys can I have a help, please? I don't really understand why my code fails it seems good to me and on the input as stated in the example it work. The problem that I'm finding really hard on this platform is why code that work fails and the platform doesn't give you a lot of information on what's wrong. Any way this is my code if someone can check it and help me to figure out what's wrong I'll be very grateful.
You didn't consider the condition that the symbol '|' should not be at the beginning or end of the melody, and also should not be next to each other.
https://dmoj.ca/src/6520873 There is my submission. Can someone help me to understand where is my mistake ?
Thanks to you guys, I did succeed to get the right result. Thanks for leaving the comments
Don´t forget taking care about the "B".
do you mean the composition with 'B' as the only tone?
That totally fooled me for ages! As usual with these things, the key seems to be really taking time to understand the question and also make sure that all the sample cases produce the results as per the sample outputs!
Whats a NameError?
EDIT Found the problem I misspelled a variable at the end :)
Check for this test case as well If there is an equal number of main tones, determine the scale based on the last tone (which is guaranteed to be either A for -minor or C for -major in any such test case).
Why is the first sample output C-Major? There is 1 A and 1 E, which makes 2 notes for a-minor, while there is only 1 C, so 1 note for C-Major. The description says the final note only decides the key if the number of notes in a-minor and C-Major are the same.
Write a program to decide if a composition is more likely written in A-minor or C-major by counting whether there are more main tones of A-minor or of C-major among the accented tones (the first tones in each measure).
So you count only the first note, and since there's only A and C, and C is the last note, it's C-major
A thing to check if your code is failing only some of the tests. In case the total main notes of A-minor and C-major are equal, the determining factor is not the last main note, but the last note of the entire composition.
Thank you! The light bulb popped up when I read what you wrote.