zoukankan      html  css  js  c++  java
  • nyoj 25-A Famous Music Composer(字符串)

    25-A Famous Music Composer


    内存限制:64MB 时间限制:1000ms Special Judge: No
    accepted:4 submit:9

    题目描述:

    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

    题目大意:
      ①、每一行,给你两个字符串,判断第一个字符串是否属于表格一中有“=”符号的字符串,属于就输出与之相同的字符串,至于第二个字符串,照抄下来就行了,但是如果不属于有“=”连接的字符串,就要输出UNIQUE

    分析:
      ①、我们可以看出具有“=”关系的前三个字符第一个元素差1,而第二个相对固定,酱紫考虑问题就简洁很多了

    核心代码:  
     1 if(s1[1] == '#')
     2 {
     3     if(s1[0] == 'G')
     4         printf("Ab %s
    ", s2);
     5     else
     6         printg("%cb %s
    ", s1[0]+1, s2);
     7 }
     8 else if(s1[1] == 'b')
     9 {
    10     if(s1[0] == 'A')
    11         printf("G# %s
    ", s2);
    12     else
    13         printf("%c# %s
    ", s1[0]-1, s2);
    14 }
    15 else
    16 {
    17     printf("UNIQUE
    ");
    18 }

    C/C++代码实现(AC):

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cmath>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <queue>
     7 #include <set>
     8 #include <map>
     9 #include <stack>
    10 
    11 using namespace std;
    12 
    13 int main ()
    14 {
    15     char s1[10], s2[10];
    16     int cnt = 1;
    17     while(~scanf("%s %s", &s1[0], &s2[0]))
    18     {
    19         printf("Case %d: ", cnt ++);
    20         if(s1[1] == '#')
    21         {
    22             if(s1[0] == 'G')
    23             {
    24                 printf("Ab %s
    ", s2);
    25             }
    26             else
    27             {
    28                 printf("%cb %s
    ", s1[0]+1, s2);
    29             }
    30         }
    31         else if(s1[1] == 'b')
    32         {
    33             if(s1[0] == 'A')
    34             {
    35                 printf("G# %s
    ", s2);
    36             }
    37             else
    38             {
    39                 printf("%c# %s
    ", s1[0]-1, s2);
    40             }
    41         }
    42         else
    43         {
    44             printf("UNIQUE
    ");
    45         }
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    完美主义之我见
    职场-位置思维
    我的读书观
    人力资源是组织的第一战略资源-论基层员工
    积累是做成事情得唯一途径
    地理信息数据处理之我见
    word 之 插入删除空行
    OSMeteorTranslationAPI(百度,有道)对比
    CsharpOSMeteorCodeGenerator(Metero代码生成器)
    HtmlDOM 文档读取研究
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9066764.html
Copyright © 2011-2022 走看看