zoukankan      html  css  js  c++  java
  • A Famous Music Composer

                                                               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
    ","A#",str2);
                else if(strcmp(str1,"A#")==0)
                    printf("%s %s
    ","Bb",str2);
                else if(strcmp(str1,"C#")==0)
                    printf("%s %s
    ","Db",str2);
                else if(strcmp(str1,"Db")==0)
                    printf("%s %s
    ","C#",str2);
                else if(strcmp(str1,"D#")==0)
                    printf("%s %s
    ","Eb",str2);
                else if(strcmp(str1,"Eb")==0)
                    printf("%s %s
    ","D#",str2);
                else if(strcmp(str1,"F#")==0)
                    printf("%s %s
    ","Gb",str2);
                else if(strcmp(str1,"Gb")==0)
                    printf("%s %s
    ","F#",str2);
                else if(strcmp(str1,"G#")==0)
                    printf("%s %s
    ","Ab",str2);
                else if(strcmp(str1,"Ab")==0)
                    printf("%s %s
    ","G#",str2);
                else
                    printf("UNIQUE
    ");
    
    
        }
        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;  
    }  

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

  • 相关阅读:
    ajax traditional
    阿里云OSS NET SDK 引用示范程序
    js对象的两种写法
    BZOJ NOIP提高组十连测第一场
    ikbc 时光机 F87 Ctrl 失灵 解决办法
    【读书笔记】阅读的危险
    51nod 1118 机器人走方格 解题思路:动态规划 & 1119 机器人走方格 V2 解题思路:根据杨辉三角转化问题为组合数和求逆元问题
    【算法】求逆元模板
    【复习资料】软件工程之快速原型模型
    VirtualBox安装linux mint教程
  • 原文地址:https://www.cnblogs.com/lipching/p/3850550.html
Copyright © 2011-2022 走看看