Editorial for COCI '12 Contest 5 #1 Ljestvica


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

The basic idea: We use a variable Amin to count accented tones that are main tones in A-minor, and a variable Cmaj to count accented tones that are main tones in C-major.

Implementation details: One traversal (using a for-loop) over the input string is used to find accented tones in the following way: a tone is accented if it is the first character in the string, or if the previous character was |. For each accented tone, we can use a branching statement (such as if-then-else or switch-case) to check whether it is equal to C, F, or G (in which case we increment the variable Cmaj), or to A, D, or E (in which case we increment the variable Amin).

Finally, it is obvious what we need to output if Amin < Cmaj or if Amin > Cmaj. If, on the other hand, Amin = Cmaj, we simply need to check whether the last character of the input string is A or C, as defined in the problem statement.


Comments


  • 0
    flaccidpancake  commented on Aug. 7, 2025, 11:08 p.m.

    Last bash used by the judge doesnt work. Could someone spot the bug please?

    scale=input()
    A_mol=0
    C_dur=0
    
    cond= True
    
    for l in scale:
        if l in ['A','D','E'] and cond:
            A_mol+=1
            cond= False
        elif l in ['C','F','G'] and cond:
            C_dur+=1
            cond= False
        if l=='|':
            cond= True
    
    if A_mol==C_dur:
        if scale[-1] in ['C']:
            C_dur+=1
        if scale[-1] in ['A']:
            A_mol+=1
    
    
    if A_mol<C_dur:
        print('C-dur')
    else:
        print('A-mol')

    • 0
      flaccidpancake  commented on Aug. 7, 2025, 11:17 p.m.

      nevermind fixed; however I hate american music annotation and music. I aint no musician.