码迷,mamicode.com
首页 > 其他好文 > 详细

A Famous Music Composer

时间:2014-11-29 11:41:36      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   ar   color   os   sp   java   for   

描述

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# 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 minor
D# major
G minor
样例输出
Case 1: G# minor
Case 2: Eb major
Case 3: UNIQUE

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     public static void main(String[] args) {
 5         Scanner scanner=new Scanner(System.in);
 6         String s1;
 7         String s2;
 8         String compare="A B C D E F G";
 9         String output=null;
10         int time;
11         
12         time=1;
13         while(scanner.hasNext()){
14             s1=scanner.next();
15             s2=scanner.next();
16             
17             if(compare.indexOf(s1)!=-1)
18                 output="UNIQUE";
19             
20             else if(s1.compareTo("A#")==0)
21                 output="Bb"+" "+s2;
22             
23             else if(s1.compareTo("Bb")==0)
24                 output="A#"+" "+s2;
25             
26             else if(s1.compareTo("C#")==0)
27                 output="Db"+" "+s2;
28             
29             else if(s1.compareTo("Db")==0)
30                 output="C#"+" "+s2;
31             
32             else if(s1.compareTo("D#")==0)
33                 output="Eb"+" "+s2;
34             
35             else if(s1.compareTo("Eb")==0)
36                 output="D#"+" "+s2;
37             
38             else if(s1.compareTo("F#")==0)
39                 output="Gb"+" "+s2;
40             
41             else if(s1.compareTo("Gb")==0)
42                 output="F#"+" "+s2;
43             
44             else if(s1.compareTo("G#")==0)
45                 output="Ab"+" "+s2;
46             
47             else if(s1.compareTo("Ab")==0)
48                 output="G#"+" "+s2;
49             
50             System.out.println("Case "+time+": "+output);
51             time++;
52         }
53         
54         
55         
56     }
57 }

 

 

A Famous Music Composer

标签:des   style   blog   ar   color   os   sp   java   for   

原文地址:http://www.cnblogs.com/zqxLonely/p/4130389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!