http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=25161
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
String str[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E",
"F", "F#", "G", "G#", "A", "A#", "B" };
int n = Integer.parseInt(scn.nextLine()), count = 0, x;
for (int i = 0; i < n; i++) {
String s = scn.nextLine();
char c[] = s.toCharArray();
if (s.indexOf("m") > 0)
count = 1;
else
count = 0;
String s1[] = s.split("m");
x = call(s1);
if (count == 1)
System.out.println(str[x] + " " + str[x + 3] + " " + str[x + 4 + 3]);
else
System.out.println(str[x] + " " + str[x + 4] + " " + str[x + 4 + 3]);
}
}
public static int call(String[] s) {
int x = 0;
if (s[0].equals("C"))
x = 0;
else if (s[0].equals("C#"))
x = 1;
else if (s[0].equals("D"))
x = 2;
else if (s[0].equals("D#"))
x = 3;
else if (s[0].equals("E"))
x = 4;
else if (s[0].equals("F"))
x = 5;
else if (s[0].equals("F#"))
x = 6;
else if (s[0].equals("G"))
x = 7;
else if (s[0].equals("G#"))
x = 8;
else if (s[0].equals("A"))
x = 9;
else if (s[0].equals("A#"))
x = 10;
else if (s[0].equals("B"))
x = 11;
return x;
}
/*
題目:[Problem 1] 和絃組成音
作者:1010
時間:西元 2016 年 7 月 */
}
這題用s.indexOf("m")>0判斷輸入字串裡面是否有m,然後進入call()判斷是在第幾個開始
沒有留言:
張貼留言