A famous music composer

Source: Internet
Author: User

A famous music composer

Time limit:1000 msMemory limit:0 KB64bit Io format:% LLD & % LlU

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 t 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.

Input

Each test case is described by one line having the formatNote tonality, WhereNoteIs one of the 17 names for the scale notes given above, andTonalityIs eitherMajorOrMinor. All notes names will be uppercase.

Output

For each case output the required answer, following the format of the sample.

Example
Input: Ab minorD# majorG minor

Output: Case 1: G# minorCase 2: Eb majorCase 3: UNIQUE


Solution: determine one by one, and output aliases with aliases; Output unique without aliases can be implemented in multiple ways

Your own code:

#include<stdio.h>#include<string.h>int main(){    char str1[10],str2[10];    int t;    t=1;    while(~scanf("%s %s",str1,str2))    {            printf("Case %d: ",t++);            if(strcmp(str1,"Bb")==0)                printf("%s %s\n","A#",str2);            else if(strcmp(str1,"A#")==0)                printf("%s %s\n","Bb",str2);            else if(strcmp(str1,"C#")==0)                printf("%s %s\n","Db",str2);            else if(strcmp(str1,"Db")==0)                printf("%s %s\n","C#",str2);            else if(strcmp(str1,"D#")==0)                printf("%s %s\n","Eb",str2);            else if(strcmp(str1,"Eb")==0)                printf("%s %s\n","D#",str2);            else if(strcmp(str1,"F#")==0)                printf("%s %s\n","Gb",str2);            else if(strcmp(str1,"Gb")==0)                printf("%s %s\n","F#",str2);            else if(strcmp(str1,"G#")==0)                printf("%s %s\n","Ab",str2);            else if(strcmp(str1,"Ab")==0)                printf("%s %s\n","G#",str2);            else                printf("UNIQUE\n");    }    return 0;}

!!! Note the string expression, the output of strcmp (str1, "A #") and ".

Better code on the Internet:

#include<iostream>  #include<map>  using namespace std;  int main()  {      map<string,string> m;      m["A#"]="Bb"; m["C#"]="Db";      m["D#"]="Eb"; m["F#"]="Gb";      m["G#"]="Ab"; m["Ab"]="G#";      m["Gb"]="F#"; m["Db"]="C#";      m["Bb"]="A#"; m["Eb"]="D#";      int i=1;      string a,b;      while(cin>>a>>b)      {          cout<<"Case "<<i++<<": ";          if(m[a]=="")           cout<<"UNIQUE"<<endl;          else           cout<<m[a]<<" "<<b<<endl;      }      return 0;  }  

Hope to provide more and better methods ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.