Skip to content

Commit a6add3c

Browse files
committed
new one
1 parent 4318a73 commit a6add3c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

chord.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
string notes[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };
6+
7+
int getindex(string s) {
8+
for (int i = 0; i < 12; i++) {
9+
if (notes[i] == s)
10+
return i;
11+
}
12+
return 0;
13+
}
14+
15+
string check (int index1, int index2, int index3){
16+
int first_tones, second_tones, third_tones;
17+
18+
if (index2 < index1) {
19+
first_tones = index2 + 12 - index1;
20+
}
21+
else {
22+
first_tones = index2 - index1;
23+
}
24+
if (index3 < index2) {
25+
second_tones = index3 + 12 - index2;
26+
}
27+
else {
28+
second_tones = index3 - index2;
29+
}
30+
31+
if (first_tones == 4 && second_tones == 3)
32+
return "major";
33+
34+
else if (first_tones == 3 && second_tones == 4)
35+
return "minor";
36+
37+
else
38+
return "strange";
39+
}
40+
41+
42+
int main() {
43+
int index1, index2, index3;
44+
45+
string s1, s2, s3;
46+
string s[6];
47+
48+
49+
cin >> s1 >> s2 >> s3;
50+
51+
52+
index1 = getindex(s1);
53+
index2 = getindex(s2);
54+
index3 = getindex(s3);
55+
56+
57+
s[0] = check(index1, index2, index3);
58+
s[1] = check(index1, index3, index2);
59+
s[2] = check(index2, index1, index3);
60+
s[3] = check(index2, index3, index1);
61+
s[4] = check(index3, index1, index2);
62+
s[5] = check(index3, index2, index1);
63+
64+
int i = 0;
65+
while(i < 6){
66+
if(s[i] == "major" || s[i] == "minor"){
67+
cout << s[i] << endl;
68+
return 0;
69+
}
70+
i++;
71+
}
72+
73+
cout << "strange" << endl;
74+
return 0;
75+
}

0 commit comments

Comments
 (0)