"10415 looks very simple", I had thought until I sent my prog...
Now, I don't know, what can be checked after trying and trying.
I mentioned:
- song may be empty -> printing only '0' 10 times
- at most 200 notes in a song -> inputstring of size 300!
- first note -> all fingers required
- further notes -> only pressed, if not used in note before
- numbers seperated by single space...
I'm asking for some test cases because I have no idea what I could try now...
I have tried to solve this problem several times with various algorithm but all of them give me wrong answer. Can anybody explain me the tips to solve this problem. Thanks in advance.
i can't understand the problem..
that is why i can't solve this..
will anybody please tell about the problem in easy words..?
i will be greatful to him/her...
i contact yahoo but he gives me no better suggestion..
will you help?
anupam
"Everything should be made simple, but not always simpler"
For the sample input : cdefgab
why the output is 0 1 1 1 0 0 1 1 1 1.
Because in the first note, finger 2~4, 7~10 were used; then in 2nd note(d), no finger was used; in 3rd note e, finger 2~4, 7, 8 were used. So why finger 2 is used only once?
First note: c .. 2 3 4 7 8 9 10
Second note: d .. 2 3 4 7 8 9 .. 10 was released, no new fingers pressed
Third not: e .. 2 3 4 7 8 .. 9 was released, no new fingers pressed
Only increment the finger count, if it requires you to use a finger to produce the new note from the previous note.
Hi, I have tested my program with an infinity of inputs, and it seems correct to me. However, it still evaluates to WA in the judge. Could anyone take a look at it, or send me some inputs of your one? Thanks!
#include <stdio.h>
#include <string.h>
#define MAXLENGTH (10)
#define MAXKEYS (500)
short counters[MAXLENGTH];
short usage[MAXLENGTH];
char song[MAXKEYS + 1];
void processFingers(short *list, int size){
for (int i = 0; i < size; i++)
if (usage[list - 1] == 0){
usage[list - 1] = 1;
counters[list - 1]++;
}
for (int i = MAXLENGTH; i > 0; i--)
for (int j = 0; j < MAXLENGTH; j++){
if (list[j] < i){
usage = 0;
break;
}
else if (list[j] == i)
break;
}
}
void processNote(char c){
short list[MAXLENGTH];
int counter = 0;
switch (c){
case 'c': list[counter++] = 10;
case 'd': list[counter++] = 9;
case 'e': list[counter++] = 8;
case 'f': list[counter++] = 7;
case 'g': list[counter++] = 4;
case 'a': list[counter++] = 3;
case 'b': list[counter++] = 2; break;
case 'C': list[counter++] = 3; break;
case 'D': list[counter++] = 9;
case 'E': list[counter++] = 8;
case 'F': list[counter++] = 7;
case 'G': list[counter++] = 4;
case 'A': list[counter++] = 3;
case 'B': list[counter++] = 2; list[counter++] = 1; break;
}
processFingers(list,counter);
}
void solve(void){
int size = (int)strlen(song);
for (int i = 0; i < size; i++){
processNote(song);
}
}
int main(void){
int n;
scanf("%d%*c",&n);
for (int i = 0; i < n; i++){
for (int i = 0; i < MAXLENGTH; i++){
counters = 0;
usage = 0;
}
song[0] = '\0';
gets(song);
solve();
for (int i = 0; i < MAXLENGTH - 1; i++)
printf("%d ",counters);
printf("%d\n",counters[MAXLENGTH - 1]);
}
return 0;
}
//10415 Eb Alto Saxophone Player
#include <iostream>
using namespace std;
//if finger press on one button;
//then isPress[finger]=true;
bool isPress[11];
//store the number of total press of every finger
int pressNum[11];
char music[210];
void press(int finger)
{
if(!isPress[finger])
{
pressNum[finger]++;
isPress[finger]=true;
}
}
void play(char note)
{
int i;
//finger press part
switch(note)
{
case 'c':press(10);
case 'd':press(9);
case 'e':press(8);
case 'f':press(7);
case 'g':press(4);
case 'a':press(3);
case 'b':press(2);break;
case 'C':press(3);break;
case 'D':press(9);
case 'E':press(8);
case 'F':press(7);
case 'G':press(4);
case 'A':press(3);
case 'B':press(2);
default:press(1);break;
}
//here is finger un-press part
switch(note)
{
case 'b':isPress[3]=false;
case 'a':isPress[4]=false;
case 'g':isPress[7]=false;
case 'f':isPress[8]=false;
case 'e':isPress[9]=false;
case 'd':isPress[10]=false;
case 'c':isPress[1]=false;break;
case 'C':
for(i=1;i<=10;i++)
isPress[i]=false;
isPress[3]=true;
break;
case 'B':isPress[3]=false;
case 'A':isPress[4]=false;
case 'G':isPress[7]=false;
case 'F':isPress[8]=false;
case 'E':isPress[9]=false;
case 'D':isPress[10]=false;
default:break;
}
}
int main(int argc,char *argv[])
{
long n;
long i;
cin>>n;
while(n-->=1)
{
cin>>music;
for(i=1;i<=10;i++)
{
isPress[i]=false;
pressNum[i]=0;
}
for(i=0;music[i]!='\0';i++)
play(music[i]);
cout<<pressNum[1];
for(i=2;i<=10;i++)
cout<<' '<<pressNum[i];
cout<<endl;
}
}