码迷,mamicode.com
首页 > 其他好文 > 详细

A Famous Music Composer

时间:2014-07-18 20:03:59      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   strong   os   

                                                           A Famous Music Composer

                     Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Mr.B is a famous music composer. One of his most famous work was his set of preludes. These 24 pieces span the 24 musical keys (there are musically distinct 12 scale notes, and each may use major or minor tonality). The 12 distinct scale notes are:

 

AA# = BbBCC# = Db D
D# = Eb E F F# = Gb G G# = Ab

Five of the notes have two alternate names, as is indicated above with equals sign. Thus, there are 17 possible names of scale notes, but only 12 musically distinct notes. When using one of these as the keynote for a musical key, we can further distinguish between major and minor tonalities. This gives 34 possible keys, of which 24 are musically distinct.

In naming his preludes, Mr.B used all the keys except the following 10, which were named instead by their alternate names:

 

Ab minorA# majorA# minorC# majorDb minor
D# majorD# minorGb majorGb minorG# major

Write a program that, given the name of a key, give an alternate name if it has one, or report the key name is unique.

Input

Each test case is described by one line having the format note tonality, where note is one of the 17 names for the scale notes given above, and tonality is either major or minor. All notes names will be uppercase.

Output

For each case output the required answer, following the format of the sample.

Example

Input: Ab minor
D# major
G minor

Output: Case 1: G# minor Case 2: Eb major Case 3: UNIQUE


解题方法:逐一判断,有别名的输出别名;没有别名的输出UNIQUE    可多种方法实现

自己的代码:

#include<stdio.h>
#include<string.h>

int main()
{
    char str1[10],str2[10];
    int t;
    t=1;
    while(~scanf("%s %s",str1,str2))
    {
            printf("Case %d: ",t++);

            if(strcmp(str1,"Bb")==0)
                printf("%s %s\n","A#",str2);
            else if(strcmp(str1,"A#")==0)
                printf("%s %s\n","Bb",str2);
            else if(strcmp(str1,"C#")==0)
                printf("%s %s\n","Db",str2);
            else if(strcmp(str1,"Db")==0)
                printf("%s %s\n","C#",str2);
            else if(strcmp(str1,"D#")==0)
                printf("%s %s\n","Eb",str2);
            else if(strcmp(str1,"Eb")==0)
                printf("%s %s\n","D#",str2);
            else if(strcmp(str1,"F#")==0)
                printf("%s %s\n","Gb",str2);
            else if(strcmp(str1,"Gb")==0)
                printf("%s %s\n","F#",str2);
            else if(strcmp(str1,"G#")==0)
                printf("%s %s\n","Ab",str2);
            else if(strcmp(str1,"Ab")==0)
                printf("%s %s\n","G#",str2);
            else
                printf("UNIQUE\n");


    }
    return 0;
}

 !!!注意字符串的表达方式,strcmp(str1,"A#")和"A#"的输出。

上网看到的更加好的代码:

#include<iostream>  
#include<map>  
using namespace std;  
int main()  
{  
    map<string,string> m;  
    m["A#"]="Bb"; m["C#"]="Db";  
    m["D#"]="Eb"; m["F#"]="Gb";  
    m["G#"]="Ab"; m["Ab"]="G#";  
    m["Gb"]="F#"; m["Db"]="C#";  
    m["Bb"]="A#"; m["Eb"]="D#";  
    int i=1;  
    string a,b;  
    while(cin>>a>>b)  
    {  
        cout<<"Case "<<i++<<": ";  
        if(m[a]=="")  
         cout<<"UNIQUE"<<endl;  
        else  
         cout<<m[a]<<" "<<b<<endl;  
    }  
    return 0;  
}  

希望可以提供更多更好的方法~

A Famous Music Composer,布布扣,bubuko.com

A Famous Music Composer

标签:des   style   blog   color   strong   os   

原文地址:http://www.cnblogs.com/lipching/p/3850550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!