Lvat is studying music. In this week, he has to figure out what chords are. First of all, he needs to learn the two kinds of most basic chords - the major triad chord and the minor triad chord.
In music theory, every 12 successive notes form a loop (or formally, an octave). Practically, we denote each note in an octave from low to high as C, C#, D, D#, E, F, F#, G, G#, A, A# and B. The pitch distance between every two adjacent notes is the same,which is called a semitone. Specifically,thepitchdistance between note C in the higher octave and note B in the adjacent lower octave is also one semitone. To conceptualize this, we can mark them on the piano keyboard, one key one note, as the figure shown below. As mentioned, the pitch distance between every two adjacent key is one semitone:
Now Lvat can easily make out the two kinds of most basic chords. You can think of a chord simply as a group of different notes. Specifically, the major triad chord and the minor triad chordare both composed of three different notes, and we denote them from low to high as N1,N2 and N3:
⋅⋅ If the pitch distance between N1 and N2 is exactly 4 semitones, and that between N2 and N3 is exactly 3 semitones, we call the group of notes a major triad chord.
⋅⋅ If the pitch distance between N1 and N2 is exactly 3 semitones, and that between N2 and N3 is exactly 4 semitones, we call the group of notes a minor triad chord.
For example, consider a group of notes of <N1 = C, N2 = E, N3 = G> in the same octave. Note C and note E have a pitch distance of 4, while note E and note G have a pitch distance of 3, so it is a major triad chord.
Next consider a group of notes of <A, C, E>, where note A is in the lower octave, and note C and E are in the adjacent higher octave. Note A and note C have a pitch distance of 3, while note C and note E have a pitch distance of 4, so it is a minor triad chord.
Now Lvat needs you to help him decide which groups of notes are major triads and which ones are minor triads.
Input
The first line is a single number T (T ≤ 2000), indicating the number of groups of notes.
For the following T lines, each line contains a group of three notes N1,N2 and N3 (denoted as described before), separated by a single space. It is guaranteed that the three notes are given from low to high, and the pitch distance between N1 and N2 is no more than 11 semitones, so is N2 and N3.
Output
Output T lines.
The i-th line indicates the answer for the i-th group of notes. If the i-th group constitutes a major triad chord, output “Major triad” (without quotation marks), or if it constitutes a minor triad chord, output “Minor triad” (without quotation marks), otherwise output “Dissonance” (without quotation marks).
Sample Input
5 C E G A C E B D F# C F A E D C
Sample Output
Major triad Minor triad Minor triad Dissonance Dissonance
题目大意:
给出T组字符串,每个字符串包含三个钢琴键N1,N2,N3(N1<N2<N3),判断三个键位是Major triad、Minor triad还是Dissonance。
解题思路:
一一对比判断每个钢琴键的位置,最后在相减得出类型,注意三个键位有可能跨越两个八度。
具体代码:
#include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
char a[24][3]={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
int b[24];
while(t--)
{
int j;
char c1[3],c2[3],c3[3];
int n1,n2,n3;
scanf("%s%s%s",c1,c2,c3);
for(j=0;j<24;j++)
{
if(strcmp(c1,a[j])==0)
{
n1=j;break;
}
}
for(j=0;j<24;j++)
{
if(strcmp(c2,a[j])==0)
{
if(j<=n1)
n2=j+12;
else
n2=j;
break;
}
}
for(j=0;j<24;j++)
{
if(strcmp(c3,a[j])==0)
{
if(j<=n2)
n3=j+12;
else
n3=j;
break;
}
}
if(n2-n1==4&&n3-n2==3)
printf("Major triad\n");
else
if(n2-n1==3&&n3-n2==4)
printf("Minor triad\n");
else
printf("Dissonance\n");
}
return 0;
}