10260 - Soundex

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

Moderator: Board moderators

Royce Lu
New poster
Posts: 1
Joined: Sat Oct 12, 2002 11:00 am

10260 - Soundex

Post by Royce Lu » Sat Oct 12, 2002 11:44 am

I don't know why I always recieve WA . :cry:
Could someone give me some data?
thanks!! :)


Here is my code :

//@BEGIN_OF_SOURCE_CODE
#include <stdio.h>
void main(){
char array[25];

int i=0;
int printbuffer=0,temp=0;
while(gets(array)){
if(array[0]=='\0')
break;
for(i=0;array!='\0';i++){

if(array=='A'||array=='E'||array=='O')
{temp=0;
continue;}
else if(array=='U'||array=='H'||array=='W'||array=='Y')
{temp=0;
continue;}

else if (array=='C'||array=='G'||array[i]=='J'||array[i]=='K')
{printbuffer=2;}
else if(array[i]=='Q'||array[i]=='S'||array[i]=='X'||array[i]=='Z')
{printbuffer=2;}

else if (array[i]=='B'||array[i]=='F'||array[i]=='P'||array[i]=='V')
{printbuffer=1;}
else if (array[i]=='D'||array[i]=='T')
{printbuffer=3;}
else if (array[i]=='M'||array[i]=='N')
{printbuffer=5;}
else if (array[i]=='L')
{printbuffer=4;}
else if (array[i]=='R')
{printbuffer=6;}

if(printbuffer==temp)
continue;
else{
printf("%d",printbuffer);
temp=printbuffer;
}

}
printf("\n");
}

}

//@END_OF_SOURCE_CODE

uzioriluzan
New poster
Posts: 27
Joined: Thu Feb 14, 2002 2:00 am

Re: 10260,HELP!

Post by uzioriluzan » Tue Nov 05, 2002 4:35 pm

This is a problem from Waterloo. Maybe you could find something helpful there.
Regards!
Royce Lu wrote:I don't know why I always recieve WA . :cry:
Could someone give me some data?
thanks!! :)


Here is my code :

//@BEGIN_OF_SOURCE_CODE
#include <stdio.h>
void main(){
char array[25];

int i=0;
int printbuffer=0,temp=0;
while(gets(array)){
if(array[0]=='\0')
break;
for(i=0;array!='\0';i++){

if(array=='A'||array=='E'||array=='O')
{temp=0;
continue;}
else if(array=='U'||array=='H'||array=='W'||array=='Y')
{temp=0;
continue;}

else if (array=='C'||array=='G'||array[i]=='J'||array[i]=='K')
{printbuffer=2;}
else if(array[i]=='Q'||array[i]=='S'||array[i]=='X'||array[i]=='Z')
{printbuffer=2;}

else if (array[i]=='B'||array[i]=='F'||array[i]=='P'||array[i]=='V')
{printbuffer=1;}
else if (array[i]=='D'||array[i]=='T')
{printbuffer=3;}
else if (array[i]=='M'||array[i]=='N')
{printbuffer=5;}
else if (array[i]=='L')
{printbuffer=4;}
else if (array[i]=='R')
{printbuffer=6;}

if(printbuffer==temp)
continue;
else{
printf("%d",printbuffer);
temp=printbuffer;
}

}
printf("\n");
}

}

//@END_OF_SOURCE_CODE

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one » Tue Nov 12, 2002 7:44 pm

can anyone give me sample input/output data
what is the output for
A
ASDQWER
VBDSUEQPQOPQWEXXCZ


thx

rjhadley
Learning poster
Posts: 73
Joined: Mon Oct 14, 2002 7:15 am
Location: United States

Post by rjhadley » Fri Dec 13, 2002 6:43 am

The output should be:

2326
132212122

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

10260 Soundex Why WA

Post by shamim » Sun Feb 09, 2003 11:53 am

Could some one tell me why I get WA:


/* @begin_of_source_code */

#include<string.h>
#include<stdio.h>
int main(void)
{
char code[6][9];
char word[20];
int len,i,j;
strcpy(code[0],"BFPV");
strcpy(code[1],"CGJKQSXZ");
strcpy(code[2],"DT");
strcpy(code[3],"L");
strcpy(code[4],"MN");
strcpy(code[5],"R");

while(scanf("%s",word)!=EOF)
{
len=strlen(word);
for(i=0;i<len;i++)
{
for(j=0;j<6;j++)
{
if(strchr(code[j],word))
{
printf("%d",j+1);
if(i<len-1)
while(strchr(code[j],word))
{ i++; if(i>=len) break; }
else break;
if(i>=len) break;
j=0;
}
}
}
printf("\n");
}
return 0;
}
/* @end_of_source_code */

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Post by Red Scorpion » Thu Feb 13, 2003 5:19 am

Hai, Try this test Cases :
sample input:
AADDAAGJ
KKLPA
KL
OP
PPPPAOAOOOAOOSDF
MMNBGDF
AAPQOW
ZZZZX
XXZ
PPPQOHIAKL
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZXY
HIJKL
MNOPAS
QRTS
APA

Sampe Output:
32
241
24
1
1231
51231
12
2
2
1224
1231224512623122
2
24
512
2632
1

8) 8)
GOOD LUCK!

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal » Fri Feb 21, 2003 7:44 pm

try by this:
char code[6][20];
in place of
char code[6][9];
and increase the size of word

efr_shovo
New poster
Posts: 38
Joined: Wed Sep 22, 2004 9:09 am

10260 Why W.A

Post by efr_shovo » Sat Sep 25, 2004 9:59 am

Please Help me Why 10260 Gives Wrong ans.


#include<stdio.h>
#define MAX 300

char s[MAX];
char str[1000];
int i;
char ch;
void main()
{

s['B']='1';
s['F']='1';
s['P']='1';
s['V']='1';

s['C']='2';
s['G']='2';
s['J']='2';
s['K']='2';
s['Q']='2';
s['S']='2';
s['X']='2';
s['Z']='2';

s['D']='3';
s['T']='3';

s['L']='4';

s['M']='5';
s['N']='5';

s['R']='6';

while(gets(str))
{
while(str)
{

if(ch!=s[str]&&s[str]!='\0')

putchar(s[str]);
ch=s[str];
i++;
}
printf("\n");
i=0;
}
}

User avatar
jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz » Tue May 31, 2005 11:00 pm

thanks for I/O!
It was very useful for me!!;)
keep it real!

shaikat
New poster
Posts: 8
Joined: Mon Jul 21, 2003 7:55 am

10260 - Soundex why got WA

Post by shaikat » Fri Jul 29, 2005 8:17 pm

Can anyone help about 10260. I have got WA. I have post the code below:

Code: Select all

#include<stdio.h>



char al[255];
int i,memory,flag;
char str[85];

void main()
{

	//freopen("C:\\IN.TXT","r",stdin);
	//freopen("C:\\OUT1.TXT","w",stdout);


	al['A']='\0';
	al['B']='1';
	al['C']='2';
	al['D']='3';al['E']='\0';al['F']='1';al['G']='2';al['H']='\0';
	al['I']='\0';al['J']='2';al['K']='2';al['L']='4';al['M']='5';al['N']='5';
	al['O']='\0';al['P']='1';al['Q']='2';al['R']='6';al['S']='2';al['T']='3';
	al['U']='\0';al['V']='1';al['W']='\0';al['X']='2';al['Y']='\0';al['Z']='2';

	while(scanf("%s",str)!=EOF)
	{
		flag=0;
		i=0;
		while(str[i])
		{
			if(flag==0)
			{
				for(;al[str[i]]=='\0';i++);
				memory=al[str[i]]-48;
				putchar(al[str[i]]);
				flag=1;
			}
			if(al[str[i]]!='\0')
			{
				if(memory!=al[str[i]]-48)
					{putchar(al[str[i]]);memory=al[str[i]]-48;}
			}
			else
				memory=-1;
			i++;

		}
		if(flag!=0)
			printf("\n");

	}
}
pls help me........... :)

shaikat
New poster
Posts: 8
Joined: Mon Jul 21, 2003 7:55 am

Modified but Still got WA

Post by shaikat » Wed Aug 03, 2005 7:18 pm

I have modified the code in the following way. But I still got WA.


Code: Select all

#include<stdio.h>


char al[255];
int i,memory,flag;
char str[85];

void main()
{

	freopen("C:\\in.txt","r",stdin);
	freopen("C:\\OUT1.TXT","w",stdout);


	al['A']='\0';
	al['B']='1';
	al['C']='2';
	al['D']='3';al['E']='\0';al['F']='1';al['G']='2';al['H']='\0';
	al['I']='\0';al['J']='2';al['K']='2';al['L']='4';al['M']='5';al['N']='5';
	al['O']='\0';al['P']='1';al['Q']='2';al['R']='6';al['S']='2';al['T']='3';
	al['U']='\0';al['V']='1';al['W']='\0';al['X']='2';al['Y']='\0';al['Z']='2';

	while(scanf("%s",str)!=EOF)
	{
		flag=0;
		i=0;
		while(str[i])
		{
			/*if(flag==0)
			{
				for(;al[str[i]]=='\0';i++);
				memory=al[str[i]]-48;
				putchar(al[str[i]]);
				flag=1;
			} */
			if(al[str[i]]!='\0')
			{
				if(memory!=al[str[i]]-48)
					{putchar(al[str[i]]);memory=al[str[i]]-48;}
			}
			else
				memory=-1;
			i++;

		}
		/*if(flag!=0)*/
			printf("\n");

	}
}
pls help me.................................. :D :(

shaikat
New poster
Posts: 8
Joined: Mon Jul 21, 2003 7:55 am

10260 - plzzzzzzzzzzzzzz help

Post by shaikat » Tue Aug 09, 2005 8:37 pm

Any one pls help me why i got WA.

Code: Select all

#include<stdio.h> 


char al[255]; 
int i,memory,flag; 
char str[85]; 

void main() 
{ 

//   freopen("C:\\in.txt","r",stdin); 
  // freopen("C:\\OUT1.TXT","w",stdout); 


   al['A']='\0'; 
   al['B']='1'; 
   al['C']='2'; 
   al['D']='3';al['E']='\0';al['F']='1';al['G']='2';al['H']='\0'; 
   al['I']='\0';al['J']='2';al['K']='2';al['L']='4';al['M']='5';al['N']='5'; 
   al['O']='\0';al['P']='1';al['Q']='2';al['R']='6';al['S']='2';al['T']='3'; 
   al['U']='\0';al['V']='1';al['W']='\0';al['X']='2';al['Y']='\0';al['Z']='2'; 

   while(scanf("%s",str)!=EOF) 
   { 
      flag=0; 
      i=0; 
      while(str[i]) 
      { 
         if(al[str[i]]!='\0') 
         { 
            if(memory!=al[str[i]]-48) 
               {putchar(al[str[i]]);memory=al[str[i]]-48;} 
         } 
         else 
            memory=-1; 
         i++; 

      } 
         printf("\n"); 

   } 
} 

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Re: 10260 - plzzzzzzzzzzzzzz help

Post by tan_Yui » Thu Aug 11, 2005 2:52 am

Hi, shaikat.
After checking the following input, try to debugging :)

Input :

Code: Select all

KHAWN
PFISTER
BOBBY
AADDAAGJ
KKLPA
KL
OP
PPPPAOAOOOAOOSDF
MMNBGDF
AAPQOW
ZZZZX
XXZ
PPPQOHIAKL
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZXY
HIJKL
MNOPAS
QRTS
APA
Output should be :

Code: Select all

25
1236
11
32
241
24
1
1231
51231
12
2
2
1224
1231224512623122
2
24
512
2632
1
(This input set are written in old log of this board, and checked again using my code now. Thanks!)

Best regards.

shaikat
New poster
Posts: 8
Joined: Mon Jul 21, 2003 7:55 am

thanks

Post by shaikat » Thu Aug 11, 2005 9:00 pm

Many many thanks tan_Yui. At last, i have got AC.

Thanks again.

-shaikat :D

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

10260

Post by abhi » Mon Dec 05, 2005 2:48 pm

here is my code i get WA..... i have tried the test cases mentioned in this site and i seem to be getting the right ans .........

Code: Select all

#include<stdio.h>


int main()
{
	char s[100],c;
	int a=0,n=0;
   
	s['B']=1;s['F']=1;s['P']=1;s['V']=1;
	s['C']=2;s['G']=2;s['J']=2;s['K']=2;s['Q']=2;s['S']=2;s['X']=2;s['Z']=2;
	s['D']=3;s['T']=3;
	s['L']=4;
	s['M']=5;s['N']=5;
	s['R']=6;
	while((c=getchar())!=EOF)

	{
	  if(c==10){printf("\n");	continue;}
	  n=s[c];
		if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'||c=='H'||c=='W'||c=='Y')
			{
				a=n;
				continue;
         }
		else if(n!=a)
			{
			printf("%d",s[c]);
			a=n;
			}
		

	}
return 0;
}


Post Reply

Return to “Volume 102 (10200-10299)”