您的位置:首页 > 其它

杭电OJ第4245题 A Famous Music Composer

2015-04-15 22:11 435 查看
  杭电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:
AA#=BbBCC#=DbDD#=EbEFF#=GbGG#=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# 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: