DMOPC '18 Contest 3 P1 - Bob and Music Class

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Bob is studying for his music theory exam and needs your help!

In music, there are 12 distinct tones. They are named, in ascending order, A, A#, B, C, C#, D, D#, E, F, F#, G, and G#. (Note that there is no B# or E#.) After G#, the sequence cycles back to A and repeats. The distance between two adjacent tones is one semitone.

The interval between two tones a and b is the distance in semitones from tone a to tone b. For example, the interval between F and A# is 5 semitones (F -> F# -> G -> G# -> A -> A# = 5 steps from F to A#) and the interval between A# and F is 7 semitones (A# -> B -> C -> C# -> D -> D# -> E -> F).

A triad is a certain kind of sequence of 3 tones (ex. F#, A, C#). There are 4 types of triads. If the intervals between the first and second tones and the second and third tones are 4 and 3 semitones respectively, the triad is major (ex. C, E, G). If they are 3 and 4, the triad is minor (ex. C, D#, G). If they are 4 and 4, the triad is augmented (ex. C, E, G#). If they are 3 and 3, the triad is diminished (ex. C, D#, F#).

Triads can come in 3 different inversions. A triad in root position follows one of the 4 interval patterns described above (ex. E, G#, B). A triad in first inversion has a cyclic shift of 1 to the left from its root position (ex. G#, B, E), and a triad in second inversion has a cyclic shift of 2 to the left from its root position (ex. B, E, G#).

The first tone of the triad when it is shifted to root position is known as its root. For example, the root of G#, B, E is E and the root of C, D#, G is C.

Given a triad, help Bob find its root, type, and inversion.

If the given triad is augmented, assume it is in root position.

Input Specification

3 lines with a valid tone on each line. The i-th line contains the i-th tone of the triad.

The triad represented by the tones is guaranteed to be a valid major, minor, augmented, or diminished triad in root position, first inversion, or second inversion.

Output Specification

Output the root of the triad, the type of the triad (major, minor, augmented, or diminished), and the inversion of the triad (root position, first inversion, or second inversion), each on its own line.

Note that the augmented triad is unique in that its first and second inversions can also be augmented triads in another root (for example, C, E, G# can be root-position with root C or first-inversion with root G#). Thus, if the given triad is augmented, assume it is in root position.

Sample Input 1


Sample Output 1

root position

Sample Input 2


Sample Output 2

second inversion

Sample Input 3


Sample Output 3

root position


  • 7
    GD_FrostByte  commented on Nov. 18, 2018, 10:19 a.m.

    where are the flats and double sharps and double flats

    • 9
      Riolku  commented on Jan. 4, 2019, 11:45 a.m.

      Please it's painful enough