492 - Pig-Latin
Moderator: Board moderators
TLE Again
Hi Jan,
Thnx for replying. I implemented the changes u said in your post and my time wierdly increased from 10.076 to 10.111! How can this be possible?
Thnx for replying. I implemented the changes u said in your post and my time wierdly increased from 10.076 to 10.111! How can this be possible?
AFter 10 seconds(limit) the judge automatically terminates the program. So, 10.076 to 10.111 is nothing(or you can say its for termination process).
Can you post your code? Remove the previous one.
Can you post your code? Remove the previous one.
Ami ekhono shopno dekhi...
HomePage
HomePage
The code - the only thing i`ve changed is the vstrcat function
Code: Select all
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int isvowel(char a)
{
if(a=='a'||a=='A'||a=='e'||a=='E'||a=='i'||a=='I'||a=='o'||a=='O'||a=='u'||a=='U')
return 1;
else
return 0;
}
void vstrcat(char p[],char q,int l)
{
int x=l;
p[x+1]=p[x];
p[x]=q;
}
void vput(char a[],char b[],int x,int y)
{
int i,l=strlen(a);
for(i=x;i<=y;i++,l++)
vstrcat(a,b[i],l);
}
void process(char a[],char b[])
{
int i,s,e,state=0,bl,l=strlen(a);
for(i=0;i<l;i++)
{
if(isalpha(a[i]))
{
if(state==0)
{
state=1;
s=i;
}
}
else
{
if(state==1)
{
e=i-1;
if(isvowel(a[s]))
{
vput(b,a,s,e);
strcat(b,"ay");
}
else
{
vput(b,a,s+1,e);
bl=strlen(b);
vstrcat(b,a[s],bl);
strcat(b,"ay");
}
}
state=0;
bl=strlen(b);
vstrcat(b,a[i],bl);
}
if((i==(l-1))&&(state))
{
e=l-1;
if(isvowel(a[s]))
{
vput(b,a,s,e);
strcat(b,"ay");
}
else
{
vput(b,a,s+1,e);
bl=strlen(b);
vstrcat(b,a[s],bl);
strcat(b,"ay");
}
}
}
}
int main()
{
char a[2000000],b[2000000];
while(gets(a))
{
if(!strlen(a))
break;
b[0]='\0';
process(a,b);
printf("%s\n",b);
}
return 0;
}
There are still..
Remove these. The reason is simple. Suppose b[] has 100000 characters, then strlen(b) will take a lot of time. After that if you add one character to b again, your code will find strlen(b) again. Thats why you are getting TLE.
Code: Select all
l=strlen(a);
...
bl=strlen(b);
Ami ekhono shopno dekhi...
HomePage
HomePage
Spoiler ahead...
I m describing my algorithm..
Hope it helps.
I m describing my algorithm..
Code: Select all
1. Read the line ( like gets(a) )
2. i = j = 0
3. if a[i] is a letter
4. b[j] = a[i]
5. j++
6. i++
7. goto 3
8. else // a[i] is not a letter
9. if j>0
10. process b and print
11. j = 0
12. if a[i] = NULL then print a new line and goto 1
13. print a[i]
14. i++
15. goto 3
Ami ekhono shopno dekhi...
HomePage
HomePage
Thanks
Thanks for the algo.. Saw the same logic in some other post here.. Too lazy to change my program to that
.. Was trying to somehow make my program fit into the timeframe! Guess i`ll have to make big changes now.. Thanks for ur help

-
- Learning poster
- Posts: 53
- Joined: Sat Jul 29, 2006 7:33 am
- Location: (CSE,DU), Dhaka,Bangladesh
why WA?(492)piglatin
Code: Select all
The code is removed after ac.
Last edited by ishtiaq ahmed on Sun Feb 17, 2008 7:32 pm, edited 1 time in total.
-
- Learning poster
- Posts: 62
- Joined: Sun Jul 09, 2006 8:31 am
- Location: University of Dhaka
- Contact:
492 why WA
i search
but i can not found any solution 
but i can not found any solution
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define isalphabet(c) ((c>='a' && c<='z') || (c>='A' && c<='Z'))
#define vowel(n) (n=='a' || n=='e' || n=='i' || n=='o' || n=='u' || n=='A' || n=='E' || n=='I' || n=='O' || n=='U')
int main()
{
char str[2000000];
int l,i,j,k,m;
while(gets(str))
{
l=strlen(str);
i=0; k=0; j=0;
while(isalphabet(str[0]) && i<l)
{
if(vowel(str[i]))
{
for(j=i;isalphabet(str[j]) ; j++)
{
printf("%c",str[j]);
}
printf("ay%c",str[j]);
i=j+1;
}
else if(!(vowel(str[i])))
{
m=i;
for(k=i+1; isalphabet(str[k]); k++)
{
printf("%c",str[k]);
}
printf("%cay%c",str[m],str[k]);
i=k+1;
}
else
printf("%c",str[i]);
}
}
return 0;
}

-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
You've been warned many times not to create a new thread for a problem if there are existing threads in which to post in.
If you keep doing this, your post will be deleted without further warning.
If you keep doing this, your post will be deleted without further warning.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.
-
- New poster
- Posts: 1
- Joined: Tue Jun 19, 2007 5:51 am
492 WA
Could somebody give me some test data
or tell me the error in the code?
I cannot find. Thanks a lot.
or tell me the error in the code?
I cannot find. Thanks a lot.
#include<stdio.h>
int main()
{
char input[10000];
int i, j;
int temp;
while( fgets(input, 10000, stdin) )
{
i=0;
temp=0;
while(input!='\0')
{
if( ( input>=65 && input<=90 ) || ( input>=97 && input<=122) )
{
if( input[i-1]<65 || (input[i-1]>90 && input[i-1]<97) || input[i-1]>122 )
{
if(input==65 || input==69 || input==73 || input==79 || input==85
|| input[i]==97 || input[i]==101 || input[i]==105 || input[i]==111 || input[i]==117)
{
printf("%c", input[i]);
}
else
{
temp=input[i];
}
}
else
{
printf("%c", input[i]);
}
if( input[i+1]<65 || (input[i+1]>90 && input[i+1]<97) || input[i+1]>122 )
{
if(temp!=0)
{
printf("%c", temp);
temp=0;
}
printf("ay");
}
}
else
{
printf("%c", input[i]);
}
i++;
}
}
}
Search the board first. And dont open new threads if one already exists.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 38
- Joined: Tue Jul 17, 2007 3:21 pm
- Location: East West University
492 TLE,help needed

i am getting TLE for this prob. Plz help with tips. how can I make it faster
Code: Select all
DELETED AFTER AC :-)
Last edited by Fuad Hassan EWU on Wed Aug 01, 2007 6:30 am, edited 1 time in total.
Eagle er moto daana meley urbo