ZOJ-1274

没啥难度的模拟题,按规则写就是了

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值