492 - Pig-Latin
Moderator: Board moderators
492 - Pig-Latin
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;
}
#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;
}
clarification of 492, 494
here "word" is defined as consequtive sequence of letters.
according to these problems...
are the following strings "word"s?
adc....asd
...as
as123adasd
according to these problems...
are the following strings "word"s?
adc....asd
...as
as123adasd
492 got WA why?
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?
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?
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
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
help
why I got RTE???
who can help me???
[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]
who can help me???

[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]
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
492 RTE
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'!
[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'!