Page 1 of 2

### 449 - Majoring in Scales - Bad Input?

Posted: Wed May 22, 2002 1:46 am
The question states:
"For the purposes of this problem, we are only concerned with the following major scales: C, Db, D, Eb, E, F, Gb, G, Ab, A, Bb, and B."

However, the input contains keys which are not of this set.
The problem does not specify what to do with such keys, yet the acceptance rate is still quite high.

Does anyone know what to do for this case?

Thanks

Gilbert

### hI~~

Posted: Wed May 22, 2002 5:01 am
Why are you sure that there are input cases that are not the scales specified?

I just solved the problem by what the problem description stated...

Posted: Thu Apr 20, 2006 8:35 am
Can anyone kindly provide some sample input? I find the problem description a little ambiguous and got like 10 WA already. Thanks.

Posted: Thu Apr 20, 2006 10:12 am
And can someone explain the problem in plain-and-easy-to-understand language? I don't understand at all what the problem's want...

Posted: Wed Nov 29, 2006 7:30 am
Does anyone can give me some critical I/O for my WA code? Code: Select all

``````/* removed after AC */
``````

Posted: Wed Nov 29, 2006 7:31 am
Does anyone can give me some critical I/O for my WA code? Code: Select all

``````/* removed after AC */
``````

Posted: Wed Nov 29, 2006 11:27 pm
Try the samples

Input:

Code: Select all

``````Bb
Bb UP SECOND;Bb UP THIRD;Bb UP FOURTH;Bb UP FIFTH;Bb UP SIXTH;Bb UP SEVENTH;Bb UP OCTAVE``````
Output:

Code: Select all

``````Key of Bb
Bb: UP SECOND > C
Bb: UP THIRD > D
Bb: UP FOURTH > Eb
Bb: UP FIFTH > F
Bb: UP SIXTH > G
Bb: UP SEVENTH > A
Bb: UP OCTAVE > Bb``````
Hope it helps.

Posted: Sat Dec 02, 2006 2:55 am
Yes, I got AC now. I forgot about the "fifth".... so I add it.
Thank you Jan.

Posted: Sat Dec 02, 2006 4:04 am
You are welcome. Use the edit option and remove your code. Thanks.

Posted: Sun Mar 18, 2007 7:39 pm
Can't understand the statement well.

What does this statement mean ?
The scale may not contain a combination of both flat (b) notes and sharp (#) notes.

Posted: Sun Mar 18, 2007 11:57 pm
Hi,

it means that

Code: Select all

``C D Fb E# G A B C``
is not a valid major scale-notation.
In fact the correct notation is

Code: Select all

``C D E F G A B C``
Cu, Erik Posted: Mon Mar 19, 2007 8:11 am
For input:

Code: Select all

``````Db
D# UP THIRD;F UP SECOND
E
F# DOWN FOURTH;Gb DOWN FOURTH
``````
I got

Code: Select all

``````Key of Db
D#: UP THIRD > F#
F: UP SECOND > Gb

Key of E
F#: DOWN FOURTH > C#
Gb: DOWN FOURTH > Db
``````
Is this right ?

Posted: Mon Mar 19, 2007 8:40 am
Hello,

the major scale of Db is

Code: Select all

``Db Eb F Gb Ab Bb C Db``
Hence D# is not in the scale - for "D# UP THIRD" you have to output

Code: Select all

``D#: invalid note for this key``
Same goes for Gb in Key of E.

Cu, Erik Posted: Mon Mar 19, 2007 10:38 am
Thanks, Erik I got AC.
I was totaly misinterpreting the problem.

Thanks again.

### 449 - Majoring in Scales

Posted: Thu Dec 20, 2007 3:55 pm
Why I got WA

Code: Select all

``````#include <stdio.h>
#include <string.h>

char list =
{
{ "C",  "B#" },
{ "C#", "Db" },
{ "D",  "D"  },
{ "D#", "Eb" },
{ "E",  "Fb" },
{ "F",  "E#" },
{ "F#", "Gb" },
{ "G",  "G"  },
{ "G#", "Ab" },
{ "A",   "A" },
{ "A#", "Bb" },
{ "B",  "Cb" }
};
char scale;

int find( char * );
void Build_scale( char * , int, int );
int chislo_to_int( char * );
int find_in_scale( char * );

int main()
{
char str;
char key;

while( gets(key) )
{
gets( str );

printf( "Key of %s\n", key );

int int_key = find( key );

Build_scale( key, int_key , 0);

int i = 0;
while( str[i] != 0 )
{
char key_in = { 0, 0, 0,0};
int k = 0;
while( str[i] != ' ' ) key_in[k++] = str[i++];
key_in[k] = 0;
i++;
if( key_in == '#' )  Build_scale( key, int_key , 1);
else Build_scale( key, int_key , 0);
int int_key_in = find_in_scale( key_in );
if( int_key_in == -1 )
{
printf("%s: invalid note for this key\n",key_in);
while(str[i] != ';' && str[i] != 0 ) i++;
if( str[i] != 0) i++;

continue;
}

int i_vector;

if( str[i] == 'U') i_vector = 1;
else i_vector = -1;

char vec={0,0,0,0,0,0};
k = 0;

while( str[i] != ' ' ) vec[k++] = str[i++];
vec[k] = 0;
i++;

char chislo;
int ichislo;
k = 0;

while( str[i] != ';' && str[i] != 0 )
chislo[k++] = str[i++];
chislo[k] = 0;
if(str[i] != 0 ) i++;

ichislo = chislo_to_int( chislo );

int_key_in = int_key_in + i_vector*ichislo;
if(int_key_in < 0) int_key_in = 7 + int_key_in;
int_key_in = int_key_in %7;

printf("%s: %s %s > %s\n", key_in, vec, chislo, scale[int_key_in] );
}
printf("\n");

}
return 0;
}

int find(char *ptr)
{
for(int i = 0; i < 12; i++ )
{
if( !strcmp(ptr,list[i]) || !strcmp(ptr,list[i]) ) return i;
}
return -1;
}

void Build_scale( char *ptr, int n, int flag)
{
strcpy(scale, ptr);

int ms = { 2,2,1,2,2,2,0,0,0 };
if( ptr == 0 && flag == 0)
for(int i = 0; i < 7; i++)
{
n = ( n + ms[i] ) % 12;
if( list[n] == 0 ) strcpy( scale[i+1], list[n] );
else
if( list[n] == 'b' ) strcpy( scale[i+1], list[n] );
else strcpy( scale[i+1], list[n] );
}
if( ptr == 0 && flag == 1 )
for(int i = 0; i < 7; i++)
{
n = ( n + ms[i] ) % 12;
if( list[n] == 0 ) strcpy( scale[i+1], list[n] );
else
if( list[n] == '#' ) strcpy( scale[i+1], list[n] );
else strcpy( scale[i+1], list[n] );
}
if( ptr == 'b' )
for(int i = 0; i < 7; i++)
{
n = ( n + ms[i] ) % 12;
if( list[n] == 'b' ) strcpy( scale[i+1], list[n] );
else
if( list[n] == 'b' ) strcpy( scale[i+1], list[n] );
else strcpy( scale[i+1], list[n] );
}
if( ptr == '#' )
for(int i = 0; i < 7; i++)
{
n = ( n + ms[i] ) % 12;
if( list[n] == '#' ) strcpy( scale[i+1], list[n] );
else
if( list[n] == '#' ) strcpy( scale[i+1], list[n] );
else strcpy( scale[i+1], list[n] );
}
}

int chislo_to_int(char *ptr)
{
if(!strncmp("SECOND"  ,ptr,6)) return 1;
if(!strncmp("THIRD"   ,ptr,5)) return 2;
if(!strncmp("FOURTH"  ,ptr,6)) return 3;
if(!strncmp("FIFTH"   ,ptr,5)) return 4;
if(!strncmp("SIXTH"   ,ptr,5)) return 5;
if(!strncmp("SEVENTH" ,ptr,7)) return 6;
if(!strncmp("OCTAVE"  ,ptr,6)) return 7;
return 0;
}
int find_in_scale( char *ptr)
{
for(int i = 0; i < 7; i++)
if( !strcmp( ptr, scale[i] ) ) return i;
return -1;
}
``````

May be I not understand this problem?