346 - Getting Chorded

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

Moderator: Board moderators

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

346 - Getting Chorded

Post by Caesum » Tue Jul 23, 2002 11:49 pm

My attempts at this problem seem to continually meet in failure. It is surely just straightforward looking for three notes in sequence with gaps of 2 or 3 and my program interprets the sample data fine, and it works with test that I can think of. Is there some musical thing I am overlooking here, or some strangeness of input data ?

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

Post by Caesum » Tue Jul 30, 2002 8:12 pm

my WA code: comments welcome :)
Last edited by Caesum on Wed Jul 31, 2002 6:31 pm, edited 1 time in total.

wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

Post by wyvmak » Wed Jul 31, 2002 2:25 am

Try, in name2[], add "B#" under "C". "Fb" under "E". "E#" under "F". "Cb" under "B"

xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland

Post by xenon » Wed Jul 31, 2002 8:48 am

Thanks wyvmak, this solves a long standing WA for me...

(B# Fb G is a C Major chord.)

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev » Wed Jul 31, 2002 8:59 am

Thanks wyvmak! A very useful hint though I'm surprised that these notes can exists...

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

Post by Caesum » Wed Jul 31, 2002 6:32 pm

Yes, thanks.

This is obviously some kind of musical thing since it is not a part of the problem as given. As you can see my musical knowledge is somewhat lacking :)

User avatar
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

346 Getting Chorded Help me

Post by angga888 » Sun Dec 22, 2002 5:16 pm

Help me.
Please test my input :

b# fb g
c# e# a#
Ab cb eb
C E F#
C Eb G
c# a f#
f g# C
B# e# A
eb Bb Gb
cb Eb Gb
Eb F# a#
b eb f#
c fb g
db F Ab
db E# Ab

What the output will be?
And could you give me some another creative input and the correct output?

Thanx.
Angga :D

User avatar
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

346 Getting Chorded -- WA

Post by angga888 » Mon Jan 06, 2003 8:14 am

Help me.
Tell me if any of them are wrong.

b# fb g is a C Major chord.
c# e# a# is a A# Minor chord.
Ab cb eb is a Ab Minor chord.
C E F# is unrecognized.
C Eb G is a C Minor chord.
c# a f# is a F# Minor chord.
f g# C is a F Minor chord.
B# e# A is a F Major chord.
eb Bb Gb is a Eb Minor chord.
cb Eb Gb is a B Major chord.
Eb F# a# is a Eb Minor chord.
b eb f# is a B Major chord.
c fb g is a C Major chord.
db F Ab is a Db Minor chord.
db E# Ab is a Db Major chord.

And, if you don't mind, please give me another tricky inputs.

Regards,
Angga888

rfcotta
New poster
Posts: 7
Joined: Mon Aug 12, 2002 12:13 am

346 - Possibly something wrong with data

Post by rfcotta » Sun Apr 13, 2003 10:34 am

Hi all,

I've been trying to solve the Get Chordered problem, with no success.

After some "googleing", I found an answer to this problem, and compared the output produced by my program with the other one. For my surprise, I found these two lines were different:

***** My program
cb Eb Gb is a B Major chord.
b eb f# is a B Major chord.

***** The program I found
cb Eb Gb is unrecognized.
b eb f# is unrecognized.

Hey, cb Eb Gb forms a B Major!!! Anyone who plays the guitar or the piano can confirm this! But, the program I found, that suposedely got an accepted doesn't state this.

Here's my solution, and sorry if I got anything else wrong...
[c]
#include <stdio.h>
#include <string.h>

#define MAJOR 1
#define MINOR 2

int v[3];

void strlow (char * s)
{
register int i, len = strlen(s);

for (i = 0; i < len; i++)
{
if ((s >= 'A') && (s <= 'Z')) s += 'a' - 'A';
}
}

int get_note_val (char * s)
{
char vs[10];
strcpy(vs, s);
strlow(vs);

if ((!strcmp("c", vs)) || (!strcmp("b#", vs))) return 0;
else if ((!strcmp("c#", vs)) || (!strcmp("db", vs))) return 1;
else if ((!strcmp("d", vs))) return 2;
else if ((!strcmp("d#", vs)) || (!strcmp("eb", vs))) return 3;
else if ((!strcmp("e", vs)) || (!strcmp("fb", vs))) return 4;
else if ((!strcmp("f", vs)) || (!strcmp("e#", vs))) return 5;
else if ((!strcmp("f#", vs)) || (!strcmp("gb", vs))) return 6;
else if ((!strcmp("g", vs))) return 7;
else if ((!strcmp("g#", vs)) || (!strcmp("ab", vs))) return 8;
else if ((!strcmp("a", vs))) return 9;
else if ((!strcmp("a#", vs)) || (!strcmp("bb", vs))) return 10;
else if ((!strcmp("b", vs)) || (!strcmp("cb", vs))) return 11;

assert(0);
}

int build_chord (const int i1, const int i2, const int i3)
{
int dist = v[i3] - v[i1];
if (dist < 0) dist += 12;

if (dist == 7)
{
dist = v[i2] - v[i1];
if (dist < 0) dist += 12;

if (dist == 4) return MAJOR;
if (dist == 3) return MINOR;
}

return 0;
}

char upper (char c)
{
if ((c >= 'a') && (c <= 'z')) return (c + ('A' - 'a'));
return c;
}

void trans_name (char * tmp)
{
tmp[0] = upper(tmp[0]);
tmp[2] = '\0';

if (tmp[1] == 'b')
{
tmp[1] = '#';
switch (tmp[0])
{
case 'C': tmp[0] = 'B'; tmp[1] = 0; return;
case 'D': tmp[0] = 'C'; return;
case 'E': tmp[0] = 'D'; return;
case 'F': tmp[0] = 'E'; tmp[0] = '\0'; return;
case 'G': tmp[0] = 'F'; return;
case 'A': tmp[0] = 'G'; return;
case 'B': tmp[0] = 'A'; return;
}
}

else if (tmp[1] == '#')
{
switch (tmp[0])
{
case 'E': tmp[0] = 'F'; tmp[1] = 0; return;
case 'B': tmp[0] = 'C'; tmp[1] = 0; return;
}
}

}

int main(int argc, char *argv[])
{
char s[3][5], org[3][5];
int r, p; register int i;

while (scanf("%s %s %s\n", s[0], s[1], s[2]) == 3)
{
for (i = 0; i < 3; i++)
{
v = get_note_val(s);
strcpy(org, s);
strlow(s);
}

/* 0 1 2, 0 2 1, 1 0 2, 1 2 0, 2 0 1, 2 1 0 */
if ((r = build_chord(0, 1, 2)) > 0) p = 0;
else if ((r = build_chord(0, 2, 1)) > 0) p = 0;
else if ((r = build_chord(1, 0, 2)) > 0) p = 1;
else if ((r = build_chord(1, 2, 0)) > 0) p = 1;
else if ((r = build_chord(2, 0, 1)) > 0) p = 2;
else if ((r = build_chord(2, 1, 0)) > 0) p = 2;

if (!r)
{
printf("%s %s %s is unrecognized.\n", org[0], org[1], org[2]);
}
else
{
trans_name(s[p]);
printf("%s %s %s is a %s %s chord.\n", org[0], org[1], org[2], s[p], (r == 1) ? "Major" : "Minor");
}
}

return 0;
}
[/c]

User avatar
cytse
Learning poster
Posts: 67
Joined: Mon Sep 16, 2002 2:47 pm
Location: Hong Kong
Contact:

Post by cytse » Sun Apr 13, 2003 2:16 pm

My AC program considers both cases as B Major chord.

I think there are no such test cases in judge.

rfcotta
New poster
Posts: 7
Joined: Mon Aug 12, 2002 12:13 am

Post by rfcotta » Sun Apr 13, 2003 6:28 pm

hmmm.... so I give up!

windows2k
Experienced poster
Posts: 136
Joined: Sat Apr 05, 2003 3:29 pm
Location: Taiwan

Post by windows2k » Sat Jul 12, 2003 7:52 am

rfcotta wrote:hmmm.... so I give up!
I also am confused with this question.
I found many input from network,and the discussion board before
I still get WA,could someone give me some input/output?
Thx

edfigo
New poster
Posts: 6
Joined: Mon Jun 17, 2002 2:57 am
Location: Portugal

Post by edfigo » Sun Aug 10, 2003 4:44 am

Read the last line of the problem...
You must use # instead of b, for example Ab must be G#.

I hope this helps!
edfigo

User avatar
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 » Sun Aug 10, 2003 5:10 pm

Thanks for your hint.
I've got AC. :D

angga888

txandi
New poster
Posts: 25
Joined: Sun Feb 29, 2004 2:06 am

346 - WA

Post by txandi » Sat Mar 06, 2004 10:17 pm

I need some help, please... I get WA again and again... is my code wrong??

[c]#include <stdio.h>


int chord_to_num(char a, char b)
{
int num=0;

if(a<96) num=a-'A';
else num=a-'a';

if(num==1) num++;
else if(num==2) num++;
else if(num==3) num=num+2;
else if(num==4) num=num+3;
else if(num==5) num=num+3;
else if(num==6) num=num+4;

if(b=='#') num++;
if(b=='b') num--;

return (num%12);
}




void num_to_chord(int a,char *b)
{
switch (a)
{
case 0: { b[0]='A'; b[1]='\0'; break; }
case 1: { b[0]='A'; b[1]='#'; b[2]='\0'; break; }
case 2: { b[0]='B'; b[1]='\0'; break; }
case 3: { b[0]='C'; b[1]='\0'; break; }
case 4: { b[0]='C'; b[1]='#'; b[2]='\0'; break; }
case 5: { b[0]='D'; b[1]='\0'; break; }
case 6: { b[0]='D'; b[1]='#'; b[2]='\0'; break; }
case 7: { b[0]='E'; b[1]='\0'; break; }
case 8: { b[0]='F'; b[1]='\0'; break; }
case 9: { b[0]='F'; b[1]='#'; b[2]='\0'; break; }
case 10:{ b[0]='G'; b[1]='\0'; break; }
case 11:{ b[0]='G'; b[1]='#'; b[2]='\0'; break; }
}
}



void main()
{
char a[3],b[3],c[3],a1[3],b1[3],c1[3];
int chord[3],i,j,major;

while(!feof(stdin))
{
major=-1;

scanf("%s %s %s\n",a,b,c);

chord[0]=chord_to_num(a[0],a[1]);
chord[1]=chord_to_num(b[0],b[1]);
chord[2]=chord_to_num(c[0],c[1]);

num_to_chord(chord[0],a1);
num_to_chord(chord[1],b1);
num_to_chord(chord[2],c1);

j=0;

for(i=0;j==0;i++)
{
if(((chord[0]+chord[1]+chord[2])==10)&&(chord[0]*chord[1]*chord[2]==0)&&((chord[0]==7)||(chord[1]==7)||(chord[2]==7)))
{
j=1;
major=0;
}
if(((chord[0]+chord[1]+chord[2])==11)&&(chord[0]*chord[1]*chord[2]==0)&&((chord[0]==7)||(chord[1]==7)||(chord[2]==7)))
{
j=1;
major=1;
}

if(i==20) j=1;

if(j!=1)
{
chord[0]=(chord[0]+1)%12;
chord[1]=(chord[1]+1)%12;
chord[2]=(chord[2]+1)%12;
}
}

if(major==1)
{
if(chord[0]==0) printf("%s %s %s is a %s Major chord.\n",a,b,c,a1);
if(chord[1]==0) printf("%s %s %s is a %s Major chord.\n",a,b,c,b1);
if(chord[2]==0) printf("%s %s %s is a %s Major chord.\n",a,b,c,c1);
}

else if(major==0)
{
if(chord[0]==0) printf("%s %s %s is a %s Minor chord.\n",a,b,c,a1);
if(chord[1]==0) printf("%s %s %s is a %s Minor chord.\n",a,b,c,b1);
if(chord[2]==0) printf("%s %s %s is a %s Minor chord.\n",a,b,c,c1);
}

else printf("%s %s %s is unrecognized.\n",a,b,c);

}
}


[/c]


If someone finds out what's wrong, please tell me

Thanks in advance

Post Reply

Return to “Volume 3 (300-399)”