Page 9 of 15

TLE Again

Posted: Tue Dec 26, 2006 8:36 pm
by vijay03
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?

Posted: Tue Dec 26, 2006 8:44 pm
by Jan
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.

Posted: Tue Dec 26, 2006 9:02 pm
by vijay03
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;
}


Posted: Tue Dec 26, 2006 9:13 pm
by Jan
There are still..

Code: Select all

l=strlen(a); 
...
bl=strlen(b); 
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.

Posted: Tue Dec 26, 2006 9:25 pm
by vijay03
I used strlen since the string b will be dynamically changing and it will be hard to keep track of the size of the b. I suppose i`ll have to maintain its size in a global variable.

Is that how u solved the problem? Or did u use a different method entirely?

Posted: Tue Dec 26, 2006 9:45 pm
by Jan
Spoiler ahead...
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
Hope it helps.

Thanks

Posted: Tue Dec 26, 2006 9:51 pm
by vijay03
Thanks for the algo.. Saw the same logic in some other post here.. Too lazy to change my program to that :P.. Was trying to somehow make my program fit into the timeframe! Guess i`ll have to make big changes now.. Thanks for ur help

why WA?(492)piglatin

Posted: Wed Jan 31, 2007 3:26 pm
by ishtiaq ahmed

Code: Select all

The code is removed after ac.

Posted: Wed Jan 31, 2007 3:38 pm
by helloneo
There are many threads on this problem..
Try to search first.. and don't open a new thread if there is one already..
If you need to post, use one of the old one..

Posted: Wed Jan 31, 2007 9:44 pm
by Debashis Maitra
Dear istiaq you have opened a lot of new threads
you shouldn't do that

and please send your code using code tag

492 why WA

Posted: Fri Jun 08, 2007 9:41 am
by bishop
i search
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;
}
:-?

Posted: Fri Jun 08, 2007 10:17 am
by little joey
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.

492 WA

Posted: Tue Jun 19, 2007 5:57 am
by stanleymao
Could somebody give me some test data
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++;
}
}
}

Posted: Tue Jun 19, 2007 9:36 am
by Jan
Search the board first. And dont open new threads if one already exists.

492 TLE,help needed

Posted: Tue Jul 31, 2007 11:47 pm
by Fuad Hassan EWU
:oops:
i am getting TLE for this prob. Plz help with tips. how can I make it faster

Code: Select all

DELETED AFTER AC :-)