ZOJ 1274 Getting Chorded(模拟题)

来源:互联网 发布:linux vim 保存退出 编辑:程序博客网 时间:2024/04/29 12:59
Getting Chorded

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 GC E F#G C EC Eb Gc# 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.

题目大意:本题比较难懂,具体意思就是:

乐谱由12个连续单音符(A,A#  B, C, C#, D, D#, E, F, F#, G,G#,A,A#....)可循组成,其中A#可以用Bb表示,C#可以用Db表示,D#可以用Eb表示,F#可以用Gb表示,G#可以用Ab表示。

给定3个音符 M1,M2,M3,

如果M1与M2相差数为3,M2与M3相差为2,则输出M1为高音

如果M1与M2相差数为2,M2与M3相差为3,则输出M1为低音

如果M2与M1相差数为3,M2与M3相差为2,则输出M2为高音

如果M2与M1相差数为3,M2与M3相差为2,则输出M2为低音

(通过图形和上面的文字表明列举了一些情况,还有一些情况,很容易知道,我也没有列举出来了)

/*    @author : liuwen*/#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <vector>#include <cmath>using namespace std;map<string,int>Map;int major[3];int minor[3];string toFormat(string str){    str[0]=toupper(str[0]);    if(str[1]=='b'){        switch(str[0]){            case 'B':str[0]='A';break;            case 'D':str[0]='C';break;            case 'E':str[0]='D';break;            case 'G':str[0]='F';break;            case 'A':str[0]='G';break;        }        str[1]='#';    }    return str;}void initialMap(){    Map["A"]=1;Map["A#"]=2;Map["B"]=3;Map["C"]=4;Map["C#"]=5;    Map["D"]=6;Map["D#"]=7;Map["E"]=8;Map["F"]=9;Map["F#"]=10;    Map["G"]=11;Map["G#"]=12;}int work(string sa,string sb,string sc){    int len1,len2;    if(Map[sb]<Map[sa]){        len1=Map[sb]+12-Map[sa]-1;    }else{        len1=Map[sb]-Map[sa]-1;    }    if(Map[sc]<Map[sb]){        len2=Map[sc]+12-Map[sb]-1;    }else{        len2=Map[sc]-Map[sb]-1;    }    if(len1==3&&len2==2)    return 0;    else if(len1==2&&len2==3)   return 1;    else return 2;}int main(){    //freopen("in.txt","r",stdin);    initialMap();    string s1,s2,s3;    while(cin>>s1>>s2>>s3){        string sa=toFormat(s1);        string sb=toFormat(s2);        string sc=toFormat(s3);        string theMajor="0";        string theMinor="0";        memset(major,0,sizeof(major));        memset(minor,0,sizeof(minor));        for(int i=0;i<3;i++){            switch(i){                case 0:{                    int t1=work(sa,sb,sc);                    int t2=work(sa,sc,sb);                    if(t1==0||t2==0)  major[i]=1,theMajor=sa;                    else if(t1==1||t2==1)   minor[i]=1,theMinor=sa;                    break;                }                case 1:{                    int t1=work(sb,sa,sc);                    int t2=work(sb,sc,sa);                    if(t1==0||t2==0)    major[i]=1,theMajor=sb;                    else if(t1==1||t2==1)   minor[i]=1,theMinor=sb;                    break;                }                case 2:{                    int t1=work(sc,sb,sa);                    int t2=work(sc,sa,sb);                    if(t1==0||t2==0)    major[i]=1,theMajor=sc;                    else if(t1==1||t2==1)   minor[i]=1,theMinor=sc;                    break;                }            }        }        if(theMajor!="0")  cout<<s1<<" "<<s2<<" "<<s3<<" is a "<<theMajor<<" Major chord."<<endl;        else if(theMinor!="0")  cout<<s1<<" "<<s2<<" "<<s3<<" is a "<<theMinor<<" Minor chord."<<endl;        else cout<<s1<<" "<<s2<<" "<<s3<<" is unrecognized."<<endl;    }    return 0;}


原创粉丝点击