492 - Pig-Latin

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

Post Reply
zakaria
New poster
Posts: 15
Joined: Thu Jun 27, 2002 11:34 pm

492 - Pig-Latin

Post by zakaria » Sat Jun 29, 2002 5:27 am

Please tell me why it is W.A.


#include<stdio.h>
#include<ctype.h>
#include<iostream.h>

int main()
{
int vo[10]={65,97,69,101,73,105,79,111,85,117};
int ch;
char pig[10000];
int flag=0,flag1=1,flag2=0;
int con;
long l=0;
while((ch=getchar())!=EOF)
{
if(isalpha(ch)!=0)
{
flag2=0;
if(flag==0)
{
flag1=1;
for(int i=0;i<10;i++)
if(vo==ch)flag1=0;
if(flag1==1)con=ch;
else if(flag1==0)pig[l++]=ch;
}
else pig[l++]=ch;
flag=1;
}
else
{
flag=0;
if(flag2==0)
{
if(flag1==1)pig[l++]=con;
pig[l++]='a';
pig[l++]='y';
flag2=1;
}
if(flag2==1)pig[l++]=ch;
}
}
pig[l]='\0';
cout<<pig;
return 0;
}

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard » Sat Jun 29, 2002 8:54 am

don't you think when geting 'invalid memory reference' response you should increase the 'pig' array size? or better change every 'pig[l++]=' to 'putchar('.
but there is a bug in the algo too. check the sample input without the ending dot: 'This is the input'
[/i]

zakaria
New poster
Posts: 15
Joined: Thu Jun 27, 2002 11:34 pm

Post by zakaria » Sun Jun 30, 2002 11:04 pm

I have increased the array size and the intput without the ending dot
is also correct.
pls. tell me the bug of this.

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard » Sun Jun 30, 2002 11:50 pm

i meant what if the last character is a letter? this case you will miss a possible 'ay' appending. but i rechecked the judge's input (probably ending with a newline char) and got accepeted anyway. so it's just for perfection :P

Antonio
New poster
Posts: 1
Joined: Sat Jul 13, 2002 8:31 pm

clarification of 492, 494

Post by Antonio » Sat Jul 13, 2002 8:54 pm

here "word" is defined as consequtive sequence of letters.
according to these problems...
are the following strings "word"s?

adc....asd
...as
as123adasd

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen » Sat Jul 13, 2002 10:19 pm

in this problem words are consist of only consequtive alphabets(a-z, A-Z).

adc....asd 2 words

...as 1 word

as123adasd 2 words

User avatar
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

492 got WA why?

Post by hank » Wed Jul 17, 2002 3:55 pm

What's wrong in my program?

HELP ME!!

Thanks!!!!!!!!!! :)

#include "stdio.h"
void main()
{
int i,apple;
char arry[82],k;
while(gets(arry)!=NULL){
apple=0;
for(i=0;i<=80;i++)
{

if((arry=='a'||arry=='e'||arry=='i'||arry=='o'||arry=='u')&&apple==0){
apple=1;
printf("%c",arry);
}else if((arry=='A'||arry=='E'||arry=='I'||arry=='O'||arry[i]=='U')&&apple==0){
apple=1;
printf("%c",arry[i]);
}else if(((arry[i]>='A'&&arry[i]<='Z')||(arry[i]>='a'&&arry[i]<='z'))&&apple==0){
apple=2;
k=arry[i];
}else if((!((arry[i]>='A'&&arry[i]<='Z')||(arry[i]>='a'&&arry[i]<='z')))&apple!=0)
{
if(apple==1){

if(arry[i]!=0) printf("ay%c",arry[i]);
if(arry[i]==0) printf("ay");

}else if(apple==2){

if(arry[i]!=0) printf("%cay%c",k,arry[i]);
if(arry[i]==0) printf("%cay",k);

}
apple=0;
}else{
if(arry[i]!=0)printf("%c",arry[i]);

}

if(arry[i]==0) break;

}

printf("\n");

}


}




I got WA, why?

rascle
New poster
Posts: 20
Joined: Wed Mar 06, 2002 2:00 am

Post by rascle » Wed Jul 17, 2002 5:28 pm

Hi... I got AC today...

If you need my code to produce outputs for only comparing....

You can mail to me u891504@oz.nthu.edu.tw



You can test thise case..

/*<<<<<<INPUT >>>>>>>*/

This: is, the input.
bggg)
efef


/*<<<<<<<OUTPUT>>>>>>>*/

hisTay: isay, hetay inputay.
gggbay)
efefay

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen » Sun Jul 28, 2002 4:44 pm

try using scanf("%s", a) instead of gets(a) :lol:

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen » Thu Aug 01, 2002 6:07 pm

u don't need to differentiate between '\n' or 'space'. cause here every word is important not line.
to take input using scanf
if the input is like: this is a test
and it terminates at eof use scanf like:-
[c]
char ara[100000];
while(scanf("%s", ara)==1)
{
...
...
}[/c]

cym
New poster
Posts: 15
Joined: Mon Oct 14, 2002 3:45 pm
Contact:

help

Post by cym » Sun Nov 24, 2002 11:46 am

why I got RTE???
who can help me??? :cry:

[c]
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main(void)
{
char s[10000];
int i,j,count;

while(gets(s))
{
count=0;
for(i=0;i<strlen(s);i++)
{
if((s>='A' && s<='Z') || (s<='z' && s>='a'))
{
while(((s>='A' && s<='Z') || (s<='z' && s>='a')) && i<strlen(s))
i++;
if(tolower(s[count])=='a' || tolower(s[count])=='e' ||tolower(s[count])=='i' ||tolower(s[count])=='o' ||tolower(s[count])=='u')
{
for(j=count;j<i;j++)
printf("%c",s[j]);
}
else
{
for(j=count+1;j<i;j++)
printf("%c",s[j]);
printf("%c",s[count]);
}
printf("ay%c",s);
count=i+1;
}
else
{
printf("%c",s);
count++;
}

}
printf("\n");
}
}
[/c]

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen » Sun Nov 24, 2002 7:14 pm

don't use gets, use scanf() instead. (c my post above ur's)...good luck

titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Post by titid_gede » Wed Dec 11, 2002 3:05 pm

What about consist only one letter, like..
a
b
c
it is a word?

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen » Sat Dec 14, 2002 2:27 pm

yes, it is.

Hunter
New poster
Posts: 9
Joined: Wed Feb 12, 2003 10:50 am
Location: Alaska

492 RTE

Post by Hunter » Fri Feb 14, 2003 12:41 pm

I/O seems well. Grown the array and still "Invalid Memory Reference". What's wrong with this, guys..??
[cpp]#include <stdio.h>
#include <string.h>

char str[100000],word[100000],temp,temp2;
int i,j,len,max;

void main ()
{
while (gets(str))
{
len=strlen(str); j=0;
for (i=0;i<len;i++)
{
if (str==' ')
{
max=j+1; j=0;

if (word[max-1]<65 || (word[max-1]>90 && word[max-1]<97) || word[max-1]>122)
{
temp=word[max-1]; max--;
}
if (word[0]=='a' || word[0]=='e' || word[0]=='i' || word[0]=='o' || word[0]=='u' || word[0]=='A' || word[0]=='E' || word[0]=='I' || word[0]=='O' || word[0]=='U')
{
word[max]='a';
word[max+1]='y';
}
else
{
temp2=word[0];
for (j=0;j<max-1;j++)
{
word[j]=word[j+1];
}
word[max-1]=temp2; temp2='\0';

word[max]='a';
word[max+1]='y';
}
if (temp!='\0') {word[max+2]=temp; temp='\0';}

printf ("%s",word);
printf(" ");

max+=4;
for (j=0;j<max;j++)
{
word[j]='\0';
}
j=0;

}

else {word[j]=str; j++;}
if (i==len-1)
{
max=j; j=0;

if (word[max-1]<65 || (word[max-1]>90 && word[max-1]<97) || word[max-1]>122)
{
temp=word[max-1]; max--;
}
if (word[0]=='a' || word[0]=='e' || word[0]=='i' || word[0]=='o' || word[0]=='u' || word[0]=='A' || word[0]=='E' || word[0]=='I' || word[0]=='O' || word[0]=='U')
{
word[max]='a';
word[max+1]='y';
}
else
{
temp2=word[0];
for (j=0;j<max-1;j++)
{
word[j]=word[j+1];
}
word[max-1]=temp2; temp2='\0';

word[max]='a';
word[max+1]='y';
}
if (temp!='\0') {word[max+2]=temp; temp='\0';}

printf ("%s",word);
if (i<len-1) printf(" ");

max+=4;
for (j=0;j<max;j++)
{
word[j]='\0';
}


printf ("\n");
}
str='\0';
}
}
}[/cpp]
Thank's for helpin'!

Post Reply

Return to “Volume 4 (400-499)”