449 - Majoring in Scales

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

gilbert
New poster
Posts: 4
Joined: Wed Dec 12, 2001 2:00 am

449 - Majoring in Scales - Bad Input?

Post 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
10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

hI~~

Post 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...
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Post by stcheung »

Can anyone kindly provide some sample input? I find the problem description a little ambiguous and got like 10 WA already. Thanks.
Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

Post 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...
razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue »

Does anyone can give me some critical I/O for my WA code? :(

Code: Select all

/* removed after AC */
Last edited by razor_blue on Sat Dec 02, 2006 6:20 am, edited 1 time in total.
razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue »

Does anyone can give me some critical I/O for my WA code? :(

Code: Select all

/* removed after AC */
Last edited by razor_blue on Sat Dec 02, 2006 6:15 am, edited 1 time in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue »

Yes, I got AC now. I forgot about the "fifth".... so I add it.
Thank you Jan.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

You are welcome. Use the edit option and remove your code. Thanks.
Ami ekhono shopno dekhi...
HomePage
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post 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.
Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

Post 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 :)
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post 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 ?
Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

Post 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 :)
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

Thanks, Erik :D I got AC.
I was totaly misinterpreting the problem.

Thanks again.
[Liga]Black
New poster
Posts: 2
Joined: Mon Dec 17, 2007 12:09 am

449 - Majoring in Scales

Post 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!!!!
Post Reply

Return to “Volume 4 (400-499)”