All about problems in Volume 7. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
mamun
A great helper
Posts: 286 Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:
Post
by mamun » Tue Jan 03, 2006 5:31 pm
Since you have declared i in the for loop so its scope is only in this for loop. You can't reuse i after it without redeclaring it.This is what you are doing in main(). So it can be like
Code: Select all
for(int i=0;i<10;i++)
cout<<ch1;
cout<<"NAME";
for(int i=0;i<21;i++)
cout<<ch1;
or
Code: Select all
int i;
for(i=0;i<10;i++)
cout<<ch1;
cout<<"NAME";
for(i=0;i<21;i++)
cout<<ch1;
The latter method is preferable by me.
Use appropriate tag for posting.
Munni
New poster
Posts: 9 Joined: Tue Jan 03, 2006 4:59 pm
Post
by Munni » Tue Jan 03, 2006 8:59 pm
I hv solved the CE, but still it is giving PE.I can't understand where the prblm is.Plz hlp me.
/*My code*/
#include<stdio.h>
#include<iostream.h>
#include<string.h>
char compare(char ch)
{
if((ch=='B')||(ch=='P')||(ch=='F')||(ch=='V'))
return '1';
if((ch=='C')||(ch=='S')||(ch=='K')||(ch=='G')||(ch=='J')||(ch=='Q')||(ch=='X')||(ch=='Z'))
return '2';
if((ch=='D')||(ch=='T'))
return '3';
if((ch=='L'))
return '4';
if((ch=='M')||(ch=='N'))
return '5';
if((ch=='R'))
return '6';
return '0';
}
int main(void)
{
char ch,str2[5],ch1=' ',ch2;
char tmp;
char str1[30];
int num=0,j,k,i;
for(i=1;i<10;i++)
cout<<ch1;
cout<<"NAME";
for(i=1;i<21;i++)
cout<<ch1;
cout<<"SOUNDEX CODE";
cout<<"\n";
while((ch=getchar())!=EOF)
{
if(ch=='\n')
{
strcpy(str2,"0000");
ch2=' ';
tmp=' ';
str1[num]='\0';
for(i=1;i<10;i++)
cout<<ch1;
cout<<str1;
for(i=1;i<25-num;i++)
cout<<ch1;
j=0;
k=0;
str2[j]=str1[k];
ch2=compare(str1[0]);
tmp=ch2;
j++;
k++;
while((j<=3)&&(k<num))
{
ch2=compare(str1[k]);
if(tmp!=ch2)
{
str2[j]=ch2;
if(ch2!='0')
j++;
tmp=ch2;
k++;
}
else
k++;
}
str2[4]='\0';
cout<<str2;
num=0;
cout<<"\n";
}
else
{
str1[num]=ch;
num++;
}
}
for(i=1;i<20;i++)
cout<<ch1;
cout<<"END OF OUTPUT";
return 0;
}
mamun
A great helper
Posts: 286 Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:
Post
by mamun » Tue Jan 03, 2006 9:04 pm
You're supposed to print second column from 35th column. You're doing it 1 column before.
Munni
New poster
Posts: 9 Joined: Tue Jan 03, 2006 4:59 pm
Post
by Munni » Tue Jan 03, 2006 10:08 pm
Dear solver, i hv changed my code , but still it is PE.Will u plz explain whr the prblm is.
Munni
New poster
Posts: 9 Joined: Tue Jan 03, 2006 4:59 pm
Post
by Munni » Wed Jan 04, 2006 3:31 am
Thnks .I hv fix my problem nd got AC.
Zaspire
New poster
Posts: 36 Joined: Sun Apr 23, 2006 2:42 pm
Location: Russia
Post
by Zaspire » Thu Aug 10, 2006 10:14 am
This is AC
Code: Select all
#include <stdio.h>
char res;
bool Code(char c)
{
res='a';
if (c=='A'||c=='E'||c=='I'||c=='O'||c=='U'||c=='H'||c=='W'||c=='Y') return false;
if (c=='B'||c=='F'||c=='P'||c=='V') {res='1'; return true;}
if (c=='C'||c=='G'||c=='J'||c=='K'||c=='Q'||c=='S'||c=='X'||c=='Z') {res='2'; return true;}
if (c=='D'||c=='T') {res='3'; return true;}
if (c=='L') {res='4'; return true;}
if (c=='M'||c=='N') {res='5'; return true;}
if (c=='R') {res='6'; return true;}
res=' ';
return false;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int size,length;
char in[80],out[6],*t1,*t2,last;
puts(" NAME SOUNDEX CODE");
while (scanf("%s",in)!=EOF)
{
printf(" %s",in);
t1=in;
t2=out;
size=0;
*t2=*t1;
length=1;
Code(*t1);
last=res;
t1++;
t2++;
for (;(*t1!='\0')&&(length<4);t1++,size++)
{
if (Code(*t1)&&(last!=res))
{
*t2=res;
t2++;
length++;
}
if (res!=' ')last=res;
}
for (;length<4;t2++,length++)
*t2='0';
*t2='\0';
for (;*t1!='\0';t1++,size++) ;
for (;size<24;size++) putchar(' ');
puts(out);
}
puts(" END OF OUTPUT");
return 0;
}
[/code]
Zaspire
New poster
Posts: 36 Joined: Sun Apr 23, 2006 2:42 pm
Location: Russia
Post
by Zaspire » Thu Aug 10, 2006 10:18 am
But why this WA?
Code: Select all
#include <stdio.h>
char res;
bool Code(char c)
{
res='a';
if (c=='A'||c=='E'||c=='I'||c=='O'||c=='U'||c=='H'||c=='W'||c=='Y') return false;
if (c=='B'||c=='F'||c=='P'||c=='V') {res='1'; return true;}
if (c=='C'||c=='G'||c=='J'||c=='K'||c=='Q'||c=='S'||c=='X'||c=='Z') {res='2'; return true;}
if (c=='D'||c=='T') {res='3'; return true;}
if (c=='L') {res='4'; return true;}
if (c=='M'||c=='N') {res='5'; return true;}
if (c=='R') {res='6'; return true;}
res=' ';
return false;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int size;
char in[80],out[6],*t1,*t2,last;
puts(" NAME SOUNDEX CODE");
while (scanf("%s",in)!=EOF)
{
out[4]='\0';
t1=in;
t2=out;
size=0;
*t2=*t1;
Code(*t1);
last=res;
t1++;
t2++;
printf(" %s",in);
for (;(*t1!='\0')&&(*t2!='\0');t1++,size++)
{
if (Code(*t1)&&(last!=res))
{
*t2=res;
t2++;
}
if (res!=' ')last=res;
}
for (;*t2!='\0';t2++)
*t2='0';
for (;*t1!='\0';t1++,size++) ;
for (;size<24;size++) putchar(' ');
puts(out);
}
puts(" END OF OUTPUT");
return 0;
}
Zaspire
New poster
Posts: 36 Joined: Sun Apr 23, 2006 2:42 pm
Location: Russia
Post
by Zaspire » Sat Aug 19, 2006 1:39 pm
I don't initializing memory(out).
That why WA.
Moha
Experienced poster
Posts: 216 Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:
Post
by Moha » Sun Aug 20, 2006 12:50 am
Please remove your code now!
vijay03
New poster
Posts: 33 Joined: Wed Sep 13, 2006 6:46 pm
Contact:
Post
by vijay03 » Sun Oct 08, 2006 2:48 pm
My code gives the correct answer for all the input in the problem statement and the inputs i could find on this board, but OJ still says my code gives WA. Could anyone please tell me whats the mistake in my code?
Last edited by
vijay03 on Fri Nov 24, 2006 11:57 am, edited 1 time in total.
vijay03
New poster
Posts: 33 Joined: Wed Sep 13, 2006 6:46 pm
Contact:
Post
by vijay03 » Mon Oct 09, 2006 1:53 pm
Could someone please tell me whats wrong with my code? Is there some kind of a formatting error?
ALEXANDRIA_2
New poster
Posts: 10 Joined: Tue Nov 07, 2006 2:03 pm
Location: Jakarta
Post
by ALEXANDRIA_2 » Thu Nov 23, 2006 4:21 pm
hello vijay03
try to increase your array size from b[5] to b[25]
hope u get AC soon...
Impossible is nothing
vijay03
New poster
Posts: 33 Joined: Wed Sep 13, 2006 6:46 pm
Contact:
Post
by vijay03 » Fri Nov 24, 2006 11:56 am
Thanks a lot Alexandria! Got ACC.
Fuad Hassan EWU
New poster
Posts: 38 Joined: Tue Jul 17, 2007 3:21 pm
Location: East West University
Post
by Fuad Hassan EWU » Sat Aug 04, 2007 1:22 am
I am Constantly getting PE. plz help me.
Eagle er moto daana meley urbo
zyxw
New poster
Posts: 24 Joined: Sat Mar 22, 2008 5:49 am
Location: Chennai
Contact:
Post
by zyxw » Sun Jun 22, 2008 7:03 am
I was constantly getting WA.
Although problem statement doesn't say so, when i included '
\n ' after "
END OF OUTPUT ", i got AC
I am not totally useless, because I can still be used as a bad example