A Famous Music Composer
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 460Accepted Submission(s): 271
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:
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.
A#=Bb 表示这2个串 可以互换
输入2个串 把第一个串换掉后输出 第二个直接输出 如果第一个换不掉 输出UNIQUE
#include<stdio.h>
#include<string.h>
struct haha
{
char str1[10];
char str2[10];
}a[20];
int main()
{
int cas=0,i;
char s1[100],s2[100];
strcpy(a[1].str1,"A#");
strcpy(a[1].str2,"Bb");
strcpy(a[2].str1,"Bb");
strcpy(a[2].str2,"A#");
strcpy(a[3].str1,"C#");
strcpy(a[3].str2,"Db");
strcpy(a[4].str1,"Db");
strcpy(a[4].str2,"C#");
strcpy(a[5].str1,"D#");
strcpy(a[5].str2,"Eb");
strcpy(a[6].str1,"Eb");
strcpy(a[6].str2,"D#");
strcpy(a[7].str1,"F#");
strcpy(a[7].str2,"Gb");
strcpy(a[8].str1,"Gb");
strcpy(a[8].str2,"F#");
strcpy(a[9].str1,"G#");
strcpy(a[9].str2,"Ab");
strcpy(a[10].str1,"Ab");
strcpy(a[10].str2,"G#");
while(scanf("%s %s",s1,s2)!=EOF)
{
for(i=1;i<=10;i++)
{
if(strcmp(s1,a[i].str1)==0) break;
}
if(i>10) printf("Case %d: UNIQUE\n",++cas);
else printf("Case %d: %s %s\n",++cas,a[i].str2,s2);
}
return 0;
}
本文介绍了一个简单的程序设计案例,该程序用于解决音乐键名的转换问题。通过对17种音符名称及其对应的等价名称进行映射,当输入一个包含音符和调性的键名时,程序能够输出其等价的键名或者表明该键名是独一无二的。此程序通过比较和替换等价键名,提供了一种有效的方法来处理音乐理论中常见的键名转换。
361

被折叠的 条评论
为什么被折叠?



