Eb Alto Saxophone Player
Input: standard input
Output: standard output
Time Limit: 2 seconds
Memory Limit: 16 MB
- c: finger 2~4, 7~10
- d: finger 2~4, 7~9
- e: finger 2~4, 7, 8
- f: finger 2~4, 7
- g: finger 2~4
- a: finger 2, 3
- b: finger 2
- C: finger 3
- D: finger 1~4, 7~9
- E: finger 1~4, 7, 8
- F: finger 1~4, 7
- G: finger 1~4
- A: finger 1~3
- B: finger 1~2
Write a program to help count the number of times each finger presses the button. A finger presses a button if it is needed in a note, but not used in the last note. Also, if it is the first note, every finger required presses the button.
Input
The first line of the input is a single integer t(1<=t<=1000), indicating the number of test cases. For each case, there is only one line containing the song. The only allowed characters are {'c','d','e','f','g','a','b','C','D','E','F','G','A','B'}. There are at most 200 notes in a song, and the song maybe empty.
Output
For each test case, print 10 numbers indicating the number of presses for each finger. Numbers are separated by a single space.
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();
}
}
留言
張貼留言