南阳oj 25 A Famous Music Composer (水题,字符串替换问题)

来源:互联网 发布:中联汽车电子公司 知乎 编辑:程序博客网 时间:2024/05/17 06:51

A Famous Music Composer

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
描述
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#=DbD      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# majorA# minor C# major Db minor D# major D# minorGb major Gb minor G# major 
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. 
输入
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).
输出
For each case output the required answer, following the format of the sample.
样例输入
Ab minorD# majorG minor
样例输出
Case 1: G# minorCase 2: Eb majorCase 3: UNIQUE
题意:
给定几串字符,输出变化后的 字符串。
思路:看题上的说明,实话实说,关键在于看题,题目不容易看懂。
对应法则:即除了B E外都存在A# ----Bb 类似的组合对应方式。
Ab----G# 
G#----Ab
A#----Bb
Bb----A#
C#----Db
Db----C#
D#----Eb
Eb----D#
F#----Gb
Gb----F#
难点:
关键是读懂题 case的数值的变化 可以通过 标记的方法 解决
作者:dingjiceo
代码如下:
<pre name="code" class="cpp">#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){int i,d=1,flag;char a[1000];while(gets(a)){flag=0;printf("Case %d: ",d);d++;if(a[0]=='A'&&a[1]=='b')                 { a[0]='G'; a[1]='#';}else if(a[0]=='A'&&a[1]=='#'){ a[0]='B'; a[1]='b';}else if(a[0]=='B'&&a[1]=='b') { a[0]='A'; a[1]='#';}else if(a[0]=='C'&&a[1]=='#') { a[0]='D'; a[1]='b';}else if(a[0]=='D'&&a[1]=='b') { a[0]='C'; a[1]='#';}else if(a[0]=='D'&&a[1]=='#') {a[0]='E'; a[1]='b';}else if(a[0]=='E'&&a[1]=='b') { a[0]='D'; a[1]='#';}else if(a[0]=='G'&&a[1]=='b') { a[0]='F'; a[1]='#';}else if(a[0]=='F'&&a[1]=='#'){ a[0]='G'; a[1]='b';}else if(a[0]=='G'&&a[1]=='#') { a[0]='A'; a[1]='b';}else flag=1;if(flag==0) printf("%s\n",a);else printf("UNIQUE\n");}}


0 0
原创粉丝点击