24h購物| | PChome| 登入
2013-08-11 14:24:19| 人氣1,500| 回應0 | 上一篇 | 下一篇

[UVA][樂理] 346 - Getting Chorded

推薦 0 收藏 0 轉貼0 訂閱站台


 Getting Chorded 

The ``names" of the notes on a standard 88-key piano keyboard start with A (the lowest note on the keyboard) and then proceed sequentially with A# (A-sharp), B, C, C#, D, D#, E, F, F#, G, and finally G#. After the first 12 notes are named, the pattern repeats, proceeding through the last key, which is named C. Some notes have other common names. A# may also be called Bb (B-flat), C# may be called Db, D# may be called Eb, F# may be called Gb, and G# may be called Ab. (There are still other names, like Cx, but we won't worry about those here!)

Most music includes chords, or groups of notes played at the same time. Many of these chords are given standard names. For example, the notes C, E, and G sounded together are called a C Major chord. While the particular C, E and G in the chord are frequently close together on the keyboard, for our purposes here, any C, E, and G played at the same time will constitute a C Major chord. It is the spacing between the notes on the keyboard that distinguishes a Major chord from others. As you can see, there are exactly three notes skipped between the C and the E (namely C#, D and D#), and then only two skipped between the E and the G (namely F and F#). If we start with a different note, say F#, we can easily tell that the notes in an F# Major chord are F#, A#, and C# (skipping G, G#, and A between F# and A#, and skipping B and C between A# and C#).

Another frequently encountered chord is the Minor chord. C Minor, for example, is played by sounding C, D#, and G. As you can see, C# and D are skipped between C and D#, and E, F and F# are skipped between D# and G. You should now be able to tell that the notes in an F# Minor chord are F#, A, and C#.

In this problem you will be presented with a sequence of lines, each containing the names of three notes. You are to identify if these three notes, taken together, form a Major or Minor chord. If they do, you will display the name of the chord. If they don't you'll also report that fact. Remember that the notes need not appear in the usual sequence. Case will be ignored in the input, and the symbol b will be indicated by the letter b. A blank or blanks will appear between the notes on each line, and may also precede the first note on the line or follow the third note on the line.

The output is to be in the same style as shown in the examples below; do not use b to name chords: use only # when necessary.

Sample Input

C E G
C E F#
G C E
C Eb G
c# a f#
f g# C

Sample Output

C E G is a C Major chord.
C E F# is unrecognized.
G C E is a C Major chord.
C Eb G is a C Minor chord.
c# a f# is a F# Minor chord.
f g# C is a F Minor chord.

我只聽過主旋律跨三度後跨兩度的三個音符,次旋律是先誇兩度再跨三度的三個音符。

題目要求找到三個音是哪個調的主旋律或者次旋律。

不仿建表,為了順序問題一律由小到大儲存。


#include <stdio.h>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
map<string, string> majorlib, minorlib;
map<string, int> note;
string nn[12] = {
"C", "C#", "D", "D#", "E",
"F", "F#", "G", "G#", "A",
"A#", "B"};
void build() {
int i;
for(i = 0; i < 12; i++)
note[nn[i]] = i;
for(i = 0; i < 12; i++) {
int vv[3];
vv[0] = i, vv[1] = (i+4)%12, vv[2] = (i+7)%12;
sort(vv, vv+3);
majorlib[nn[vv[0]]+nn[vv[1]]+nn[vv[2]]] = nn[i];
vv[0] = i, vv[1] = (i+3)%12, vv[2] = (i+7)%12;
sort(vv, vv+3);
minorlib[nn[vv[0]]+nn[vv[1]]+nn[vv[2]]] = nn[i];
}
}
int main() {
build();
char s[3][10];
int i, j, k;
while(scanf("%s %s %s", s[0], s[1], s[2]) == 3) {
printf("%s %s %s is ", s[0], s[1], s[2]);
int vv[3];
for(i = 0; i < 3; i++) {
if(s[i][0] >= 'a' && s[i][0] <= 'z')
s[i][0] -= 32;
if(s[i][1] == 'b') {
s[i][1] = '\0';
int tmp = note[s[i]];
tmp = (tmp-1+12)%12;
s[i][0] = nn[tmp][0];
s[i][1] = nn[tmp][1];
s[i][2] = nn[tmp][2];
}
vv[i] = note[s[i]];
}
sort(vv, vv+3);
string comb = nn[vv[0]]+nn[vv[1]]+nn[vv[2]];
if(majorlib.find(comb) == majorlib.end() &&
minorlib.find(comb) == minorlib.end())
puts("unrecognized.");
else if(majorlib.find(comb) != majorlib.end())
printf("a %s Major chord.\n", majorlib[comb].c_str());
else
printf("a %s Minor chord.\n", minorlib[comb].c_str());
}
return 0;
}

台長: Morris
人氣(1,500) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][樂理] 449 - Majoring in Scales
此分類上一篇:[UVA] 139 - Telephone Tangles

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文