A Famous Music Composer

**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#=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
来源
hdu
上传者
李如兵
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=25
问题分析:
题意大概是A#=Bb C#=Db D#=Eb F#=Gb G#=Ab
是相互可以替换的,题目要求给出其中一个,找出其对应的另一个,若没有则输出UNIQUE。刚开看不懂题目,输入中的minor,major不知道是用来干嘛的,后来发现和题没什么关系,题目只是让替换前面的。
代码:**

#include <iostream>
#include <stdio.h> 
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
using namespace std; 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
map<string,string> m;
void initMap(){
    m["A#"]="Bb";
    m["Bb"]="A#";

    m["C#"]="Db";
    m["Db"]="C#";

    m["D#"]="Eb";
    m["Eb"]="D#";

    m["F#"]="Gb";
    m["Gb"]="F#";

    m["G#"]="Ab";
    m["Ab"]="G#";
}
int main(int argc, char** argv) {
    //1.初始化对应表 
    initMap();

    //2.输入
    string str1,str2;
    int j=1;
    while(cin>>str1>>str2){
        //cout<<str1<<str2<<endl;
        cout<<"Case "<<j++<<": ";
        if(m.find(str1) != m.end()){
            cout<<m[str1]<<" "<<str2<<endl;
        }else{
            cout<<"UNIQUE"<<endl;
        }
    }  
    return 0;
}

**代码分析:
代码中使用了MAP数据结构来一一对应两个字符串。因为一共就5个,相互就是10个,所以用if条件来判断也可以。
复习一下MAP的用法:**

#include<map>
map<datatype1,datatype2> m;  //声明一个map
m.clear();  //清空整个map
map<datatype1,datatype2>::iterator iter=m.find(x);
  //在map中查找有无x,若没有则返回m.end() ,,当数据出现              // 时,它返回数据所在位置的迭代器
  if(iter != mapStudent.end())
{
       Cout<<”Find, the value is ”<<iter->second<<endl;
}
Else
{
       Cout<<”Do not Find”<<endl;
}

m[datatype1a]=datatype2b;  //对map进行赋值
datatype2b=m[datatype1a];  //读取map的值
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值