andy6804tw
10/10/2016 - 12:27 PM

## https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1356 這題是2016 10/06 CPE題目 我的解法是先把14個按鍵方法先存入陣

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1356

``````import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = Integer.parseInt(scn.nextLine());
String arr[] = { "0111001111", "0111001110", "0111001100", "0111001000", "0111000000", "0110000000",
"0100000000", "0010000000", "1111001110", "1111001100", "1111001000", "1111000000", "1110000000",
"1100000000" };
int hash[] = new int[200];
hash['c'] = 0;
hash['d'] = 1;
hash['e'] = 2;
hash['f'] = 3;
hash['g'] = 4;
hash['a'] = 5;
hash['b'] = 6;
hash['C'] = 7;
hash['D'] = 8;
hash['E'] = 9;
hash['F'] = 10;
hash['G'] = 11;
hash['A'] = 12;
hash['B'] = 13;
while (n-- != 0) {
int ans[] = new int[10], state[] = new int[10];
char c[] = scn.nextLine().toCharArray();
for (int i = 0; i < c.length; i++) {
char ary[] = arr[hash[c[i]]].toCharArray();
for (int j = 0; j < 10; j++) {
if (ary[j] == '1' && state[j] == 0) {
ans[j]++;
state[j] = 1;
}
if (ary[j] == '0')
state[j] = 0;
}
}
for (int i = 0; i < 10; i++) {
if (i != 0)
System.out.print(" ");
System.out.print(ans[i]);
}
System.out.println();
}
}
/*題目：Q:10415 - Eb Alto Saxophone Player
作者：1010
時間：西元 2016 年 10 月 */
}``````