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;
    }
  • 相关阅读:
    前端知识 | 一个简单的登录页面包含多少前端基础知识?
    SQLserver查询作业、视图、函数、存储过程中的关键字
    SQL server 数据库备份至服务器本地磁盘和其他服务器磁盘
    Linux(centos)安装vim
    CentOS6 7 8更换阿里yum源
    centos8 最小化安装 无 ifconfig,netstat 的安装
    修改MySQL用户的host属性
    阿里云NTP服务器(国内可用的NTP服务器)
    vCenter Server Appliance(VCSA )7.0 部署指南
    Chrome离线安装包最新版
  • 原文地址:https://www.cnblogs.com/yejianfei/p/2636910.html
Copyright © 2011-2022 走看看