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
raysa
New poster
Posts: 40
Joined: Wed Dec 18, 2002 4:23 pm
Location: Indonesia

Post by raysa »

Thank's angga888!
I grew mine to 1200000 and finally got AC! :D

Regards,
Raysa
Professor_Of_Love
New poster
Posts: 9
Joined: Tue Apr 01, 2003 10:03 pm
Location: Dhaka, Bangladesh

Post by Professor_Of_Love »

Now please tell me... why i am getting TLE....

[c]#include<stdio.h>
#include<ctype.h>
#include<string.h>
#define N 1500000

char str[N],tmp;
int i,j,k;

int isvowel(char ch1)
{
char ch = tolower(ch1);
if(ch!='a'&&ch!='e'&&ch!='i'&&ch!='o'&&ch!='u')
return 0;
else
return 1;
}

void main(void)
{
while(gets(str))
{
for(i=0;i<strlen(str);i++)
{
if(isalpha(str))
{
if(isvowel(str))
{
while(isalpha(str))
printf("%c",str[i++]);
printf("ay");i--;
}
else
{
tmp = str[i++];
while(isalpha(str))
printf("%c",str[i++]);
printf("%cay",tmp);i--;
}
}
else
{
printf("%c",str);
}
}
printf("\n");
}
}[/c]

Thanks!
Nick
Learning poster
Posts: 53
Joined: Sun Jan 12, 2003 4:49 am

obsolete

Post by Nick »

ttwu
New poster
Posts: 8
Joined: Tue May 13, 2003 4:31 pm

Post by ttwu »

I have problems with this problem too..
I've made the array size 1000000, but I still keep getting RTE..
I just dont know why? :(

[cpp]
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main()
{
char str[1000000],p[1000000],a;
int lena,lenp,i,j;

while(gets(str))
{
lena=strlen(str);
for (i=0,strcpy(p,"");i<=lena;i++)
{
if (isalpha(str)!=0)
{
a=str;
strcat(p,&a);
}
else
{
switch(p[0])
{
case 'A': case 'a':
case 'E': case 'e':
case 'I': case 'i':
case 'O': case 'o':
case 'U': case 'u':
printf("%say%c",p,str);
break;
default:
if (strcmp(p,"")==0) printf("%c",str);
else
{
lenp=strlen(p);
for (j=1;j<lenp;j++) printf("%c",p[j]);
printf("%cay%c",p[0],str);
}
}
strcpy(p,"");
}
}
printf("\n");
}
}
[/cpp]
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

For Hunters...

INPUTS
abc123def
a1
a.a.a.
a.a...
a1.
.a1?
1a...a
p..p
OUTPUTS
abcay123efday
aay1
aay.aay.aay.
aay.aay...
aay1.
.aay1?
1aay...aay
pay..pay
Good Luck! :D

angga888 :lol:
solo
New poster
Posts: 1
Joined: Tue Jun 24, 2003 9:15 pm
Contact:

492 - Memory Limit Exceeded - Why?

Post by solo »

I get Memory Limit Exceed. Do you know why, and how can I fix it?

[pascal]
(* solo@grad.icmc.usp.br 24/06/2003 *)
(* O problema do 'latim de porco' *)

program P492 (input, output);

const
Vogais = ['A', 'E', 'I', 'O', 'U'];

var
Frase : string;

(**************************************************************************
<Funcao>
ExisteProxima : string
[se existe proxima palavra na frase]
<Parametros por Valor>
Frase : string
[a frase a ser verificada]
**************************************************************************)
function ExisteProxima(Frase : string):boolean;

begin
ExisteProxima := (Frase <> '');
end;

(**************************************************************************
<Funcao>
ProximaPalavra : string
[a proxima palavra; cada palavra e' separada das outras por um
espaco vazio, i.e., ' ' ]
<Parametros por Referencia>
Frase : string
[onde estao as palavras; a palavra obtida e' removida]
**************************************************************************)
function ProximaPalavra(var Frase : string):string;

var
Retorno : string;
Posicao : integer;

begin
Posicao := pos(' ', Frase);
(* nao ha' mais espacos: e' a ultima palavra *)
if Posicao = 0 then
Posicao := length(Frase);
(* capturamos a palavra atual *)
Retorno := copy(Frase, 1, Posicao - 1);

(* remove a palavra atual *)
if Frase[Posicao] = ' ' then
Frase := copy(Frase, Posicao + 1, length(Frase) - Posicao)
else
Frase := '';

ProximaPalavra := Retorno;
end;

(**************************************************************************
<Funcao>
LatimDePorco : string
[a frase traduzida para 'latim de porco']
<Parametros por valor>
Frase : string
[a frase a ser traduzida para 'latim de porco']
**************************************************************************)
function LatimDePorco(Frase : string):string;

var
Retorno,
Atual : string;

begin
Retorno := '';
while ExisteProxima(Frase) do
begin
Atual := ProximaPalavra(Frase);

if upcase(Atual[1]) in Vogais then
Retorno := Retorno + Atual + 'ay' + ' '
else
Retorno := Retorno + copy(Atual, 2, length(Atual) - 1) +
Atual[1] + 'ay' + ' ';
end;
Retorno[length(Retorno)] := '.';

LatimDePorco := Retorno;
end;

(**************************************************************************
<Programa Principal>
**************************************************************************)
begin
while not eof(input) do
begin
readln(Frase);
writeln(LatimDePorco(Frase));
end;
end.
[/pascal]

thanks a lot,
Bruno Nery [ Solo ]
USP-EESC/ICMC[EComp03]
====================
solo@grad.icmc.usp.br
solo@eesc.usp.br
ICQ# 36748857
====================
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

2 == scanf("%[A-Za-z]%[^A-Za-z]", a, b )

should work..
abcd
New poster
Posts: 1
Joined: Wed Sep 24, 2003 12:08 pm

492 WA><

Post by abcd »

Code: Select all

#include<iostream>
using namespace std;

const int MAX=1000000;
int main()
{
    char str[MAX];
    while(cin.getline(str,MAX))
   {
         for(int i=0;i<strlen(str);i++)
        {
              if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))
	{
	 if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'&&str[i]!='A'&&str[i]!='E'&&str[i]!='I'&&str[i]!='O'&&str[i]!='U')
	{
	     int k=i;
	     while((str[k+1]>='A'&&str[k+1]<='Z')||(str[k+1]>='a'&&str[k+1]<='z'))
	{
	     cout<<str[k+1];
	     k++;
	}
	cout<<str[i]<<"ay";
	i=k;
	}
	else
	{
	     while((str[i+1]>='A'&&str[i+1]<='Z')||(str[i+1]>='a'&&str[i+1]<='z'))
		{
		cout<<str[i];
		i++;
		}
		cout<<str[i]<<"ay";
		}
		}
		else
		cout<<str[i];
		}
	cout<<endl;
	}
	return 0;
}

somebody can help me???
I always get WA...
Please~~~ Thanks a lot!!!
Sorry...the code so messy
Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Post by Joseph Kurniawan »

See the red check mark in this problem (acm.uva.es/cgi-bin/OnlineJudge?Volume:4) ???
the array str is only used once. You don't have to read until eof!!!
So the code should be:
void main(){
gets(str);
..........
}
Good luck!! :wink: :wink:
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.
Shaka_RDR
New poster
Posts: 23
Joined: Sat Oct 04, 2003 12:12 pm
Location: in Your Heart ^^
Contact:

Post by Shaka_RDR »

hi guys.. i need your help..... this problem keep me WA for 15 times, and RTE for 5 times (i have fixed the RTE problem, now the WA problem)

i've checked my I/O with posted before, and its correct... is there any tricky input ?

here is my code (hope you can help me... i've asked 3 friends of mine for debugging my code, and we didnt find any error..)

Code: Select all

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 1000
#define KATA 1000

void main()
{
	char kata[KATA];
	char kalimat[MAX];
	char dummy;
	char vocal[11]={'a','i','u','e','o','A','I','U','E','O'};
	long int idx;
	long int kallen;
	long int katalen;
	long int voc;
	long int ok;
	long int awal,akhir,i,j,z;
	#ifndef ONLINE_JUDGE
		freopen ("492.in","r",stdin);
		freopen ("492.out","w",stdout);
	#endif


	while (gets (kalimat))
	{
		kallen = strlen (kalimat);

		idx=0;

		awal=akhir=0;
		while (idx<kallen)
		{
			ok=1;
			memset(kata,0,KATA);
			for (;idx<kallen;idx++)
			{
				if (isalpha (kalimat[idx])!=0)
				{
					awal=idx;
					akhir=awal;
					break;
				}
				else
				{
					printf ("%c",kalimat[idx]);
					ok=0;
					break;
				}
			}

			for (;idx<=kallen&&ok==1;idx++)
			{
				if (isalpha (kalimat[idx])==0)
				{
					akhir=idx-1;
					break;
				}
			}


			if (ok==1)
			{
				for (z=0,i=awal;i<=akhir;i++,z++)
				{
					kata[z]=kalimat[i];
				}

				katalen=strlen(kata);
				voc=0;
				for (j=0;j<10;j++)
				{
					if (kata[0]==vocal[j])
					{
						voc=1;
						break;
					}
				}

				if (voc == 0)
				{
					for (i=1;i<katalen;i++)
					{
						printf ("%c",kata[i]);
					}
					printf ("%cay",kata[0]);
				}
				else
				{
					for(i=0;i<katalen;i++)
					{
						printf("%c",kata[i]);
					}
					printf ("ay");
				}
			}
			else
			{
				idx++;
			}

		}
		printf ("\n");
	}
}
Every person exists for another person. and that person exists for the other one. it's just the matter of existence...
May every person helps each other and creates a world full of joy...
problem
New poster
Posts: 27
Joined: Mon Nov 10, 2003 12:40 am

492 little problem arise.help me

Post by problem »

[c]
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define max 30000

void main()
{
char x1[max],x4[max];
char *t,*s,c;
int i=0,p=0,q=0,l=0,b=0,check=0,che=0,y;
while(gets(x1))
{
l=strlen(x1);
t=x1;
s=x1;
while(*t)
{
memset(x4,'\0',max);
s=s+q;
q=0;
b=0;
che=0;
check=0;
while(*t!=' '&&*t!='\n'&&isalpha(*t))
{
if(*t=='\0')
break;
if(p==l)
break;
i++;
p++;
x4[b++]=*t;
t++;
s++;
}
i=i+2;
while(i>0)
{
q++;
if((x4[0]=='a'||x4[0]=='A'||x4[0]=='e'||x4[0]=='E'||x4[0]=='I'||x4[0]=='i'||x4[0]=='o'||x4[0]=='O'||x4[0]=='u'||x4[0]=='U')&&che!=1)
{
che=1;
strcat(x4,"ay");
s=x4;
}
if(!(x4[0]=='a'||x4[0]=='A'||x4[0]=='e'||x4[0]=='E'||x4[0]=='I'||x4[0]=='i'||x4[0]=='o'||x4[0]=='O'||x4[0]=='u'||x4[0]=='U')&&check!=1&&isalpha(x4[0]))
{
check=1;
y=strlen(x4);
c=x4[0];
x4[y]=c;
strcat(x4,"ay");
s=x4;
s=s+1;
}
printf("%c",*s);
s=s+1;
i--;
}
q=q-2;
while(!isalpha(*t))
{
if(*t=='\0')
break;
printf("%c",*t);
t++;
q++;
p++;
}
while((!isdigit(*t))||(!isalpha(*t))||(!isgraph(*t))||(!ispunct(*t)))
{
if(*t=='\0')
break;
if(isdigit(*t)||isalpha(*t)||isgraph(*t)||ispunct(*t))
break;
printf("%c",*t);
t++;
p++;
q++;
}
}
i=0;
t=0;
q=0;
s=0;
p=0;
b=0;
check=0;
che=0;
printf("\n");
}
}


I think this is very simple problem.but i got WA.some input output is
given.plz help me.


input
========
This is the input.
He is a boy.

Object123oriented,..,.Programming
000000000
aaaaaaaaaaaa
Aaaaaaaaaaaa
computerprogrammingII
cse-1204 Computer programming II
ACM programming contest was held on 10th November, 2001 at BUET.
an a eye An A Eye Bee BEE Dhaka-1205 1st last.





output
==========
hisTay isay hetay inputay.
hisTay isay hetay inputay
ihay owhay areay ouyay
ehay isay oneay ofay hetay estbay oybay inay hetay roldway
sdajfkay ksdfjlay dklfjklsay sdkfjjay lsdjfkay sldjfkay kjsdkfjlay sdjfksdjffjkay
aaaaaaaaay bbbbbbbbbbay cccccccccay xxxxxxxxxxxxay zzzzzzzzzzay bbbbbbbbbbay nnnnnay
oiuypay rewqtay asdfay hjgay lkay nmay vbay xcay azay aqzay swxay decay frvay gtbay hynay jumay ikay olay pay
uhnjibay komay poklay aqzay swcdexay frbgtvay hynay sfjjksdday
jdsfdjday dsjdsjay eeeeeeay
eeeeeeay iiiiiiay ooooooay uuuuay aaaaaay

[\c]
osan
New poster
Posts: 47
Joined: Tue Jul 29, 2003 12:03 pm
Location: Bangladesh,Dhaka.
Contact:

492

Post by osan »

1)advice for you please dont make the code complex.

2)Do not change the case of any letter. <-is that condition ok in your code?

giving you some input & output check those for your code
INPUT
This is the input.
He is a boy.

Object123oriented,..,.Programming
000000000
aaaaaaaaaaaa
Aaaaaaaaaaaa
computerprogrammingII
cse-1205 Computer programming II
OUTPUT
hisTay isay hetay inputay.
eHay isay aay oybay.

Objectay123orienteday,..,.rogrammingPay
000000000
aaaaaaaaaaaaay
Aaaaaaaaaaaaay
omputerprogrammingIIcay
secay-1205 omputerCay rogrammingpay IIay
check those with ur output->i hope it will help u to find out your code prob.
this time WA
what next...............?
prince56k
New poster
Posts: 33
Joined: Fri Dec 12, 2003 10:32 pm
Location: BANGLADESH

492 fade up with WA

Post by prince56k »

i have already tried with all the critical input given in this topics but still i don't know what's fault in my code :(

[c]
#include<stdio.h>
#include<string.h>
char vowel[11]="AEIOUaeiou", eng[1000000], pig[1000000];
long int i,j=0,len=0,k;
void main()
{
int start,end,flag=0;
while(gets(eng)!=0)
{
len = strlen(eng);
for(i=0,j=0;i<len;i++)
{
if((eng>='A'&&eng<='Z')||(eng>='a'&&eng<='z'))
{
flag = 0;
start = i;
while((eng>='A'&&eng<='Z')||(eng>='a'&&eng<='z'))
i++;
end = --i;
for(k=0;k<10;k++)
if(vowel[k]==eng[start])
flag=1;
if(flag==1)
{
for(k=start;k<=end;k++)
pig[j++]=eng[k];
pig[j++] = 'a';
pig[j++] = 'y';
}
else if(flag==0)
{
for(k=start+1;k<=end;k++)
pig[j++]=eng[k];
pig[j++] = eng[start];
pig[j++] = 'a';
pig[j++] = 'y';
}
}
else
pig[j++]=eng;
}
pig[j]='\0';
puts(pig);
}
}
[/c]
aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

Post by aakash_mandhar »

Whoa problem your source code is so big... No offence meant you need not use memset and strcat etc.. The trick is fairly simple..

I am sending my AC code.. Hope it helps you in understanding how to tackle inputs cause it is infac very simple and once you learn i u will be able to solve many problems easily..
[c]# include<stdio.h>


int state,sv;
char ch,st;

int main()
{
st=0;sv=0;
while(1)
{
ch=fgetc(stdin);
if(ch==EOF) break;
if(state==0 && ((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')))
{
state=1;
if(ch=='a' ||ch=='e' ||ch=='i' ||ch=='o' ||ch=='u' ||ch=='A' ||ch=='E' ||ch=='I' ||ch=='O' ||ch=='U')
{
sv=0;
printf("%c",ch);
}
else
{
st=ch;sv=1;
}
}
else
if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
{
printf("%c",ch);
}
else
{

if(state==1 && sv==1) {printf("%cay",st);sv=0;state=0;}
if(state==1) {printf("ay");state=0;}
printf("%c",ch);
}

}
return 1;
}
[/c]

Aakash.. :)
...I was born to code...
orojas
New poster
Posts: 5
Joined: Tue Jul 20, 2004 6:44 pm

492 runtime error, why??

Post by orojas »

I get Runtime Error from the judge(SIGSEV-Invalid memory reference) can't see why

Here is my code:

[c]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


int esVocal(char l) {
l = toupper(l);
if(l=='A' || l=='E' || l=='I' || l=='O' || l=='U')
return 1;
else
return 0;
}

int main() {

char linea[1000000];
char pendiente;
int foundCons;
int wordStart;
int longitud;
int i;
while(gets(linea)) {
longitud = (int)strlen(linea);
wordStart = 0;
foundCons = 0;
for(i=0;i<longitud;i++) {
if(isalpha(linea)) { /*ES LETRA*/
if(wordStart==0) {
wordStart=1;
if(esVocal(linea)) {
printf("%c",linea);
}
else {
pendiente=linea;
foundCons=1;
}
}
else {
printf("%c",linea);
}
} /*SI ES NO LETRA*/
else {
if(wordStart==1) {
wordStart=0;
if(foundCons==1) {
foundCons=0;
printf("%cay%c",pendiente,linea);
}
else {
printf("ay%c",linea);
}
}
else {
printf("%c",linea);
}
}
}
}
return 0;
}[/c]
Post Reply

Return to “Volume 4 (400-499)”