zoukankan      html  css  js  c++  java
  • 杭电OJ第4245题 A Famous Music Composer

      杭电OJ第4245题,A Famous Music Composer题目链接)。

    A Famous Music Composer

    Problem Description

    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:

    A A#=Bb B C C#=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 minor A# major A# minor C# major Db minor
    D# major D# minor Gb major Gb minor G# minor

    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" (quotes for clarify).

    Output

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

    Sample Input

    Ab minor
    D# major
    G minor

    Sample Output

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

    Source

    Fudan Local Programming Contest 2012

      解题思路:逐一判断,有别名的输出别名;没有别名的输出UNIQUE

      C语言源代码如下:

    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <stdbool.h>
    
    int main (void)
    {
        int test_case = 0;
        char note[1000];
        while ( gets( note ) != NULL )
        {
            test_case ++;
            if ( note[0] == 'A' && note[1] == ' ' )
                printf( "Case %d: UNIQUE\n", test_case );
            else if ( note[0] == 'A' && note[1] == '#' )
            {
                note[0] = 'B';
                note[1] = 'b';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'B' && note[1] == 'b' )
            {
                note[0] = 'A';
                note[1] = '#';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'B' && note[1] == ' ' )
                printf( "Case %d: UNIQUE\n", test_case );
            else if ( note[0] == 'C' && note[1] == ' ' )
                printf( "Case %d: UNIQUE\n", test_case );
            else if ( note[0] == 'C' && note[1] == '#' )
            {
                note[0] = 'D';
                note[1] = 'b';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'D' && note[1] == 'b' )
            {
                note[0] = 'C';
                note[1] = '#';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'D' && note[1] == ' ' )
                printf( "Case %d: UNIQUE\n", test_case );
            else if ( note[0] == 'D' && note[1] == '#' )
            {
                note[0] = 'E';
                note[1] = 'b';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'E' && note[1] == 'b' )
            {
                note[0] = 'D';
                note[1] = '#';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'E' && note[1] == ' ' )
                printf( "Case %d: UNIQUE\n", test_case );
            else if ( note[0] == 'F' && note[1] == ' ' )
                printf( "Case %d: UNIQUE\n", test_case );
            else if ( note[0] == 'F' && note[1] == '#' )
            {
                note[0] = 'G';
                note[1] = 'b';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'G' && note[1] == 'b' )
            {
                note[0] = 'F';
                note[1] = '#';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'G' && note[1] == ' ' )
                printf( "Case %d: UNIQUE\n", test_case );
            else if ( note[0] == 'G' && note[1] == '#' )
            {
                note[0] = 'A';
                note[1] = 'b';
                printf( "Case %d: %s\n", test_case, note );
            }
            else if ( note[0] == 'A' && note[1] == 'b' )
            {
                note[0] = 'G';
                note[1] = '#';
                printf( "Case %d: %s\n", test_case, note );
            }
            else
                assert(false);
        }
        return EXIT_SUCCESS;
    }
  • 相关阅读:
    Java进阶知识32 mybatis(ibatis)入门CRUD操作【简单演示,只测DAO层】
    Java进阶知识31 SpringMVC+JDBC+Oracle 注解版整合实例
    Java进阶知识30 Struts2+Spring+Hibernate+Oracle XML版整合实例
    Java进阶知识29 Struts2+Spring+Hibernate+Oracle 注解版整合实例
    错误/异常:java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType 的解决方法
    kafka
    手动升级openssl
    解决Homebrew下载更新极慢的问题
    修改centos的源, 使其能访问阿里云服务器
    mycat学习
  • 原文地址:https://www.cnblogs.com/yejianfei/p/2636910.html
Copyright © 2011-2022 走看看