【巧枚举】#73 A. Chord

A. Chord
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya studies music.

He has learned lots of interesting stuff. For example, he knows that there are 12 notes: CC#DD#EFF#GG#ABH. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between Eand C is 8 semitones

Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.

Let's define a major triad. Let the triad consist of notes XY and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.

A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.

For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# andF — 4 semitones.

Help Vasya classify the triad the teacher has given to him.

Input

The only line contains 3 space-separated notes in the above-given notation.

Output

Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.

Sample test(s)
input
C E G
output
major
input
C# B F
output
minor
input
A B H
output
strange


这是一道音乐上的题目,说有三个琴键同时按下组成和弦,如果三个键从左到右分别相差4、3个音阶的话算作major和弦,相差4、3个则为minor,啥都不是就会很strange

给三个琴键问是哪种和弦。

枚举当然可以啦,反正也就3!=6种组合,只是感觉这么来的话没有用到算法多不高兴呀~

那么我们就先在钢琴上给他们排个序呗,排好了序之后称作A\B\C(在一个12音阶中严格从左到右),那么我们只需要判断 ABC\BCA\CAB 三种情形下是否满足相差3、4或者4、3即可。

#include <cstdio>
#include <string>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;
// http://codeforces.com/contest/88
// Chord
string notes[12]={"C","C#","D","D#","E","F","F#","G","G#","A","B","H"};

int dist(string a, string b, string c)
{
	int pos[3]={0};
	for(int i=0;i<12;i++)
	{
		if(notes[i]==a) pos[0]=i;
		if(notes[i]==b) pos[1]=i;
		if(notes[i]==c) pos[2]=i;
	}
	sort(pos,pos+3);
	//cout<<pos[0]<<pos[1]<<pos[2]<<endl;
	int dis[3]={	pos[1]-pos[0],
					pos[2]-pos[1],
					pos[0]+12-pos[2] };
	for(int i=0;i<3;i++)
	{
		if(dis[i]==4 && dis[(i+1)%3]==3)return 1;
		if(dis[i]==3 && dis[(i+1)%3]==4)return 2;
	}
	return 0;
}

int main()
{
	string X,Y,Z;
	cin>>X>>Y>>Z;
	int flag=dist(X,Y,Z); 
		 if(flag==1)cout<<"major";
	else if(flag==2)cout<<"minor";
	else cout<<"strange";
	return 0;
} 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值