346 - Getting Chorded
Moderator: Board moderators
346 - Getting Chorded
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 ?
my WA code: comments welcome ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
Last edited by Caesum on Wed Jul 31, 2002 6:31 pm, edited 1 time in total.
-
- Experienced poster
- Posts: 167
- Joined: Fri Oct 19, 2001 2:00 am
- Location: Saint Petersburg, Russia
346 Getting Chorded Help me
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](./images/smilies/icon_biggrin.gif)
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](./images/smilies/icon_biggrin.gif)
346 Getting Chorded -- WA
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
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
346 - Possibly something wrong with data
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]
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]
346 - WA
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
[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