Sample Input
3
cdefgab
BAGFEDC
CbCaDCbCbCCbCbabCCbCbabae
Sample Output
0 1 1 1 0 0 1 1 1 1
1 1 1 1 0 0 1 1 1 0
1 8 10 2 0 0 2 2 1 0
解法:先打表存下每一種音符的指法
一旦有新的音符就跟目前的指法比較 只要有按下的動作就++
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class UVA10415 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Map<Character, String> record = new HashMap<Character, String>();
int volume = Integer.parseInt(sc.nextLine());
record.put(' ', "0000000000");
record.put('c', "0111001111");
record.put('d', "0111001110");
record.put('e', "0111001100");
record.put('f', "0111001000");
record.put('g', "0111000000");
record.put('a', "0110000000");
record.put('b', "0100000000");
record.put('C', "0010000000");
record.put('D', "1111001110");
record.put('E', "1111001100");
record.put('F', "1111001000");
record.put('G', "1111000000");
record.put('A', "1110000000");
record.put('B', "1100000000");
for (int v = 0; v < volume; v++) {
char temp = ' ';
String str = sc.nextLine();
String record_value, former_value;
int count[] = new int[10];
for (int i = 0; i < str.length(); i++) {
record_value = record.get(str.charAt(i));
former_value = record.get(temp);
for (int j = 0; j < 10; j++) {
if (record_value.charAt(j) == '1'
&& former_value.charAt(j) == '0')
count[j]++;
}
temp = str.charAt(i);
}
for (int i = 0; i < 9; i++)
System.out.print(count[i] + " ");
System.out.println(count[9]);
}
sc.close();
}
}