COCI '12 Contest 5 #1 Ljestvica

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type

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: A-minor and C-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 12 tones of an octave \{A, A\#, B, C, C\#, D, D\#, E, F, F\#, G, G\# \} used in modern music, A-minor and C-major scales do use the tones with shortest names: A-minor is defined as an ordered septuple (A, B, C, D, E, F, G), and C-major as (C, D, E, F, G, A, B).

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 A-minor, these are A, D, and E, and in C-major, they are C, F, and G. 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 A-minor (C) is three half-tones higher than the tonic (A), while the third tone of C-major (E) is four halftones higher than the tonic (C). 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 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). 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 A-minor or C for C-major in any such test case).

For example, examine the well-known melody "Frère Jacques":

\displaystyle CD|EC|CD|EC|EF|G|EF|G|GAGF|EC|GAGF|EC|CG|C|CG|C

The character | separates measures, so the accented tones are, in order: C, E, C, E, E, G, E, G, G, E,
G, E, C, C, C, C. Ten of them (C, C, G, G, G, G, C, C, C, C) are main tones of C-major, while six (E,
E, E, E, E, E) are main tones of A-minor. Therefore, our best estimate is that the song was written in C-major.

Input Specification

The first and only line of input contains a sequence of at least 2, and at most 100, 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 C-major) or A-mol (for A-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


  • -1
    Dragoicho  commented on Sept. 22, 2022, 5:21 p.m.

    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.


    • -1
      panzer_shrek  commented on Sept. 22, 2022, 6:02 p.m. edited

      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


  • -1
    Mikola_14  commented on Sept. 3, 2022, 1:32 p.m.

    Where are the solutions?


    • -1
      panzer_shrek  commented on Sept. 3, 2022, 3:37 p.m.

      When you solve the problem.


  • -1
    chrismilne  commented on Aug. 21, 2022, 5:03 p.m.

    I keep failing batch 2 and 4. Could anyone give me any advice as to why? Thanks


  • -1
    n7eer  commented on Aug. 20, 2022, 3:50 a.m.

    Hey guys! I've been doing this problem for three days and I still can't understand why I am failing some cases. I've tried different variations of inputs but my program still works. Any advice?


  • 5
    tomme2009  commented on April 20, 2022, 3:09 p.m. edited

    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.


    • 0
      Red_Olaf  commented on May 5, 2022, 5:39 p.m.

      Thank you! The light bulb popped up when I read what you wrote.


  • -1
    xiaodre  commented on March 23, 2022, 3:40 p.m. edited

    I'm really confused with what my mistake is. You can check my code to understand what i've done. I added a lot of prints so u can check on what is being read on my program (a way i found out helps a lot at trying to correct mistakes). I used the first example as an input to check if i would be able to count the correct amount of A-minor main tones (A,D,E) C-major (C,F,G). For some random reason, the program is only reading the first letter of the input and i have no clue why...

    Please help.

    I don't know if u can see my submission but i can also post it here if anyone needs me to.

    I haven't even tried to submit it for real on the submissions, i was only running the program on the IDE. The submission is for u to see what i wrote.


    • -1
      Spitfire720  commented on March 23, 2022, 6:44 p.m.

      You can use the Sample Inputs to find out what went wrong.


      • -1
        xiaodre  commented on March 23, 2022, 8:51 p.m. edit 3

        I took ur advice and it helped a lot!

        I have gone through my code and found out what went wrong. I have corrected my mistakes but yet, there's some tests which im failing.

        I have updated my code, but don't know what im missing now. I'm assuming the max number of notes per measurement is 4, is that a problem?

        Apparently, it stops counting after some digits, its really weird...

        Btw thanks for all the help! i've noticed you're really active on the website and i sincerely thank you, in the name of all people here. One thanks isnt enough for the amout of help you give out!


        • -2
          Spitfire720  commented on March 24, 2022, 8:00 a.m.

          I don't think your algorithm for finding accented tones are right. If you input

          A|B|C|D|E|F|G

          Your program doesn't output.


          • -1
            xiaodre  commented on March 24, 2022, 12:41 p.m. edit 2

            I think i have got my code right but i still fail batch 3 (first test) and batch 6 (in the last test, "Your output (clipped)".

            Can anyone point out what's going on?


  • -1
    Jzaragoza98  commented on Jan. 26, 2022, 5:53 p.m.

    Keep failing Batch #4 and #6 and I cannot figure out why. Could somebody please help review my code and help me understand where I am going wrong?


    • 0
      Spitfire720  commented on Jan. 26, 2022, 7:22 p.m.

      If there is an equal number of main tones, determine the scale based on the last tone (which is guaranteed to be either A A for A A -minor or C C for C C -major in any such test case).

      You only need to find the last character, there is no need to iterate backwards


  • -1
    Rhumph  commented on Jan. 21, 2022, 9:37 a.m.

    Is there a way to find out what tests my code is failing on? Thanks.


    • -3
      songin5  commented on Jan. 22, 2022, 11:25 p.m. edited

      no there isn't