A Famous Music Composer

来源:互联网 发布:网络优化工程师前景 编辑:程序博客网 时间:2024/05/29 16:05

**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;  //声明一个mapm.clear();  //清空整个mapmap<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的值
原创粉丝点击