A Famous Music Composer
在杭电接触的第一道English题,费了不少力气。。。
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:
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.
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.
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
只是我从他的输入输出上面,理解了一下,尽供参考.
题中的第一个表格,决定了输入和输出的第一个条件:如果你输入字符串在这个表格中,就有输出.
输入的第二个字符有三种情况:" ", "#","b".
如果输入的第二个字符为空格,则输出
"UNIQUE";
如果输入的第二个字符为"#",则输出的第二个字符(不考虑Case n: )就为"b";同时如果输入的第一个字符为“G”,那么输出的第一个字符就为“A”,否则就把输入的第一个字符加一;
如果输入的第二个字符为"b",则输出的第二个字符(不考虑Case n: )就为"#";同时如果输入的第一个字符为“A”,那么输出的第一个字符就为“G”,否则就把输入的第一个字符减一。
以下是我的代码:
#include<stdio.h>
#include<algorithm>
#include<string>
int main()
{
char a[100];
int n,m=1;
while(gets(a)){
printf("Case %d: ",m++);
n=strlen(a);
if(a[1]==' ')
printf("UNIQUE");
else{
if(a[1]=='#'){
if(a[0]=='G')
printf("Ab");
else
printf("%cb",a[0]+1);
}
if(a[1]=='b'){
if(a[0]=='A')
printf("G#");
else
printf("%c#",a[0]-1);
}
for(int i=2;i<n;i++)
printf("%c",a[i]);
}
printf("\n");
}
return 0;
}