Page 1 of 2

449 - Majoring in Scales - Bad Input?

Posted: Wed May 22, 2002 1:46 am
by gilbert
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
by 10153EN
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
by stcheung
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
by Roby
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
by razor_blue
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
by razor_blue
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
by Jan
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
by razor_blue
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
by Jan
You are welcome. Use the edit option and remove your code. Thanks.

Posted: Sun Mar 18, 2007 7:39 pm
by rio
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.
Thanks in advance.

Posted: Sun Mar 18, 2007 11:57 pm
by Erik
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
by rio
Thanks for your reply, Erik. But still getting WA..
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
by Erik
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
by rio
Thanks, Erik :D I got AC.
I was totaly misinterpreting the problem.

Thanks again.

449 - Majoring in Scales

Posted: Thu Dec 20, 2007 3:55 pm
by [Liga]Black
Why I got WA

Code: Select all

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



char list[20][2][4] = 
					{
						{ "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[20][4];



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

int main()
{
 char str[1000000];
 char key[3];

	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[5] = { 0, 0, 0,0};
			int k = 0;
			while( str[i] != ' ' ) key_in[k++] = str[i++]; 
			key_in[k] = 0;
			i++;
			if( key_in[1] == '#' )  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[7]={0,0,0,0,0,0};
			k = 0;

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

			char chislo[8];
			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][0]) || !strcmp(ptr,list[i][1]) ) return i;
	}
	return -1;
}

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

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


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?
Please help me!!!!