题意:给你一个萨克斯演奏曲,每个音符只有固定的几个手指可以弹奏,弹奏每个音符的手指不能是上次弹奏的手指,问每个手指弹奏了多少次。
解法:暴力打表。
#include <stdio.h>
#include <string.h>
int table[14][11] =
{
0,0,1,1,1,0,0,1,1,1,1,
0,0,1,1,1,0,0,1,1,1,0,
0,0,1,1,1,0,0,1,1,0,0,
0,0,1,1,1,0,0,1,0,0,0,
0,0,1,1,1,0,0,0,0,0,0,
0,0,1,1,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,0,
0,1,1,1,1,0,0,1,1,1,0,
0,1,1,1,1,0,0,1,1,0,0,
0,1,1,1,1,0,0,1,0,0,0,
0,1,1,1,1,0,0,0,0,0,0,
0,1,1,1,0,0,0,0,0,0,0,
0,1,1,0,0,0,0,0,0,0,0,
};
int num[11], hash[255];
bool state[11];
void solve(char *data)
{
memset(num, 0, sizeof(num));
memset(state, 0, sizeof(state));
int l = strlen(data), t;
for(int i = 0; i < l; i++)
{
t = hash[data[i]];
for(int j = 1; j < 11; j++)
{
if(table[t][j] && !state[j]) num[j]++, state[j] = 1;
if(!table[t][j]) state[j] = 0;
}
}
for(int i = 1; i < 11; i++)
{
printf("%d", num[i]);
if(i == 10) printf("\n");
else printf(" ");
}
}
int main()
{
int t;
char data[205];
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;
scanf("%d", &t);
gets(data);
while(t--)
{
gets(data);
solve(data);
}
return 0;
}