Problem Description
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
题意:给定三个音符判断这三个音符是否构成大三和弦或小三和弦;
步骤:
1、将三个八度的音符以字符串数组形式存储
2、每次读入三个需要判断的音符,依次与存储的数组进行比较,并记录相邻两个音符的间隔
3、与给定条件进行比较
AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
string s[]={"C","C#","D","D#","E","F","F#","G","G#","A",
"A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#",
"B","C","C#","D","D#","E","F","F#","G","G#","A","A#",
"B"};
string n1,n2,n3;
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n1>>n2>>n3;
int cnt1,cnt2;
int i=0;
for(;;i++)
if(s[i]==n1)
break;
for(int j=i+1;;j++)
if(s[j]==n2)
{
cnt1=j-i;
i=j;
break;
}
for(int j=i+1;;j++)
if(s[j]==n3)
{
cnt2=j-i;
i=j;
break;
}
if(cnt1==4&&cnt2==3)
puts("Major triad");
else if(cnt1==3&&cnt2==4)
puts("Minor triad");
else
puts("Dissonance");
}
}