1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
| /*0 3, 4 6 8 9 11 13 15,16 18 20 21 23 25 27,28
30 32 33 35 37 39,40 42 44 45 47 49 51,
52 54 56 57 59 61 63,64 66 68 69 71 73 75
,76 78 80 81 83 85 87,88*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
/* 本来想着要判断各个字母的前缀,后来发现还可以
跨组别来求相隔的半音,所以应该想到要直接用map把
这个按键的名字当做一个下标存下来
现代音乐用七个英文字母 C D E F G A B(或其小写)来标记音名。
这七个不同高低的音,其相邻音之间的音高距离,有半音和全音之分,其中E与F 和 B与C 之间为半音关系,其余相邻音之间为全音关系。
现代钢琴键盘上的全音和半音
相邻两个琴键(包括白健和黑键)构成半音,相隔一个琴键的两键之间构成全音。
*/
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int case1;
map<string,int>shu;//map按key的ascii进行排序,而不是按输入顺序
cin>>case1;
string name[52]={"A_2","B_2",
"C_1","D_1","E_1","F_1","G_1","A_1","B_1","C","D"
,"E","F","G","A","B","c","d","e","f","g","a","b","c^1","d^1"
,"e^1","f^1","g^1","a^1","b^1","c^2","d^2","e^2","f^2","g^2","a^2","b^2","c^3","d^3"
,"e^3","f^3","g^3","a^3","b^3","c^4","d^4","e^4","f^4","g^4","a^4","b^4","c^5"};
int zhi[52]={
0,3,4,6,8,9,11,13,15,16,
18,20,21,23,25,27,28,30,32,33,
35,37,39,40,42,44,45,47,49,51,
52,54,56,57,59,61,63,64,66,68,69,71,73,75
,76,78,80,81,83,85,87,88};
for(int i=0;i<52;i++){
shu.insert(make_pair(name[i],zhi[i]));
}
// for(map<string,int>::iterator it=shu.begin();it!=shu.end();it++){
// cout<<it->first<<" "<<it->second<<endl;
// }
while(case1--) {
string s1,s2;
cin>>s1>>s2;
cout<<abs(shu[s2]-shu[s1])<<endl;
}
}
|