没啥难度的模拟题,按规则写就是了
#include<iostream>
#include<map>
#include<cstring>
#include<cctype>
#include<cstdio>
using namespace std;
int main()
{
string S[] = { "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G",
"G#" };
map<string, int> M;
for (int i = 0; i < 12; i++)
M[S[i]] = i;
M["Bb"] = 1;
M["Db"] = 4;
M["Eb"] = 6;
M["Gb"] = 9;
M["Ab"] = 11;
bool flag[12];
string s[3], temp;
while (cin >> s[0] >> s[1] >> s[2])
{
memset(flag, 0, sizeof(flag));
for (int i = 0; i < 3; i++)
{
temp = s[i];
if (islower(s[i][0]))
temp[0] = temp[0] - 'a' + 'A';
flag[M[temp]] = true;
}
bool major = false, minor = false;
int i;
for (i = 0; i < 12; i++)
if (flag[i])
{
int mid1 = (i + 4) % 12;
int mid2 = (i + 3) % 12;
int end = (i + 7) % 12;
if (flag[mid1] && flag[end])
{
major = true;
break;
}
if (flag[mid2] && flag[end])
{
minor = true;
break;
}
}
if (major)
printf("%s %s %s is a %s Major chord.\n", s[0].c_str(),
s[1].c_str(), s[2].c_str(), S[i].c_str());
else if (minor)
printf("%s %s %s is a %s Minor chord.\n", s[0].c_str(),
s[1].c_str(), s[2].c_str(), S[i].c_str());
else
printf("%s %s %s is unrecognized.\n", s[0].c_str(), s[1].c_str(),
s[2].c_str());
}
return 0;
}