用C, C#, D, F#中的任意三种语言解答和弦命名。
以下三段代码从上到下使用的分别是C,C#和F#:
#include
#include
#define x(i,j)(i^=j^=i^=j)
int main(int u,char* w[]){
char* d[]={"A","A♯","B♭","B","C♭","C","B♯","C♯","D♭","D","D♯","E♭","E","F♭","F","E♯","F♯","G♭","G","G♯","A♭"};
int p[]={0,1,1,2,2,3,3,4,4,5,6,6,7,7,8,8,9,9,10,11,-1};
int q[]={0,0,1,1,2,2,1,2,3,3,3,4,4,5,5,4,5,6,6,6,0};
char s[]="ABCDEFG";
int v[]={0,2,3,5,7,8,10};
char* t="";
char* x="";
int a[3];
int b[3];
int i,j,k,r,z,m,n;
for(i=1;ib[0]&&b[1]>b[2]){x(b[1],b[2]);x(a[1],a[2]);}
if(b[0]>b[2]&&b[0]>b[1]){x(b[0],b[2]);x(a[0],a[2]);}
if(b[1]-b[0]==2 && b[2]-b[0]==4){r=0;m=a[1]-a[0];n=a[2]-a[1];}
else if(b[2]-b[1]==2 && 7+b[0]-b[1]==4){r=1;m=a[2]-a[1];n=12+a[0]-a[2];}
else{r=2;m=12+a[0]-a[2];n=a[1]-a[0];}
if(a[r]==v[b[r]]){t="";}else{t=a[r]>v[b[r]]?"♯":"♭";}
if(m==4){x=n==3?"":"+";}else{x=n==3?"°":"m";}
printf("%c%s%s\n",s[b[r]],t,x);
}
return 0;}
using System;
class Program
{
static void Main(string[] args)
{
string[] d = { "A", "A♯", "B♭", "B", "C♭", "C", "B♯", "C♯", "D♭", "D", "D♯", "E♭", "E", "F♭", "F", "E♯", "F♯", "G♭", "G", "G♯", "A♭" };
int[] p = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, -1 };
int[] q = { 0, 0, 1, 1, 2, 2, 1, 2, 3, 3, 3, 4, 4, 5, 5, 4, 5, 6, 6, 6, 0 };
char[] s = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
int[] v = { 0, 2, 3, 5, 7, 8, 10 };
string t = "";
string x = "";
int[] a = new int[3];
int[] b = new int[3];
int i, j, k, r, z, m, n;
for (i=0; i b[0] && b[1] > b[2]) {(b[1],b[2])=(b[2],b[1]);(a[1],a[2])=(a[2],a[1]); }
if (b[0] > b[2] && b[0] > b[1]) {(b[0],b[2])=(b[2],b[0]);(a[0],a[2])=(a[2],a[0]); }
if (b[1] - b[0] == 2 && b[2] - b[0] == 4) { r = 0; m = a[1] - a[0]; n = a[2] - a[1]; }
else if (b[2] - b[1] == 2 && 7 + b[0] - b[1] == 4) { r = 1; m = a[2] - a[1]; n = 12 + a[0] - a[2]; }
else { r = 2; m = 12 + a[0] - a[2]; n = a[1] - a[0]; }
t = a[r] == v[b[r]] ? "" : (a[r] > v[b[r]] ? "♯" : "♭");
x = m == 4 ? (n == 3 ? "" : "+") : (n == 3 ? "°" : "m");
Console.WriteLine($"{s[b[r]]}{t}{x}");
}
}
}
open System
let notes = [|"A"; "A♯"; "B♭"; "B"; "C♭"; "C"; "B♯"; "C♯"; "D♭"; "D"; "D♯"; "E♭"; "E"; "F♭"; "F"; "E♯"; "F♯"; "G♭"; "G"; "G♯"; "A♭"|]
let p = [|0; 1; 1; 2; 2; 3; 3; 4; 4; 5; 6; 6; 7; 7; 8; 8; 9; 9; 10; 11; -1|]
let q = [|0; 0; 1; 1; 2; 2; 1; 2; 3; 3; 3; 4; 4; 5; 5; 4; 5; 6; 6; 6; 0|]
let s = "ABCDEFG"
let v = [|0; 2; 3; 5; 7; 8; 10|]
let swap (arr: _[]) i j =
let temp = arr.[i]
arr.[i] <- arr.[j]
arr.[j] <- temp
[]
let main args =
let mutable t = ""
let mutable x = ""
let a = Array.zeroCreate 3
let b = Array.zeroCreate 3
for arg in args do
let h = arg.Split [|' '|]
for k in 0..2 do
for j in 0..20 do
if h.[k] = notes.[j] then
a.[k] <- p.[j]
b.[k] <- q.[j]
if b.[1] < b.[0] && b.[1] < b.[2] then
swap b 0 1
swap a 0 1
if b.[2] < b.[0] && b.[2] < b.[1] then
swap b 0 2
swap a 0 2
if b.[1] > b.[0] && b.[1] > b.[2] then
swap b 1 2
swap a 1 2
if b.[0] > b.[2] && b.[0] > b.[1] then
swap b 0 2
swap a 0 2
let mutable r = 0
let mutable m = 0
let mutable n = 0
if b.[1] - b.[0] = 2 && b.[2] - b.[0] = 4 then
r <- 0
m <- a.[1] - a.[0]
n <- a.[2] - a.[1]
elif b.[2] - b.[1] = 2 && 7 + b.[0] - b.[1] = 4 then
r <- 1
m <- a.[2] - a.[1]
n <- 12 + a.[0] - a.[2]
else
r <- 2
m <- 12 + a.[0] - a.[2]
n <- a.[1] - a.[0]
if a.[r] = v.[b.[r]] then
t <- ""
else
t <- if a.[r] > v.[b.[r]] then "♯" else "♭"
if m = 4 then
x <- if n = 3 then "" else "+"
else
x <- if n = 3 then "°" else "m"
printfn "%c%s%s" s.[b.[r]] t x
0
|