Page 8 of 15

Posted: Mon Jun 12, 2006 10:35 am
by Zaspire
I compile my solutions by Dev-C++4.9.9.2 before submiting. It help but not always :evil: .

492 Pig Latin - RE

Posted: Thu Jun 29, 2006 6:31 am
by albet_januar
can someone help me for this problem??
i don't know why my solution got RE

this is my code

Code: Select all

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

void main()
{
	char kata[1000];
	int i, j, flag;
	char m;

	while(gets(kata))
	{
		flag = 1;
		for(i=0;i<strlen(kata);i++)
		{
			if(isalpha(kata[i]))
			{
				if(flag)
				{
					m = tolower(kata[i]);
					if(!(kata[i]=='a' || kata[i] == 'e' || kata[i]=='i' ||kata[i]=='o' || kata[i] =='u'))
					{
						m = kata[i];
						for(j=i;j<strlen(kata)-1&&isalpha(kata[j+1]);j++)
						{
							kata[j] = kata[j+1];
						}
						kata[j] = m;
					}
					flag = 0;
				}
			}
			else
			{
				if(isalpha(kata[i-1]))
				{
					flag = 1;
					printf("ay");
				}
			}

			printf("%c", kata[i]);
		}

		if(isalpha(kata[i-1]))
		{
        	printf("ay");
		}


		printf("\n");
	}



}

Posted: Thu Jun 29, 2006 4:45 pm
by jan_holmes
I think you have to improve the size of "char kata[1000];". I'm using 2000000 characters to make my program AC...

Hope it helps... :wink:

Posted: Fri Jun 30, 2006 8:24 pm
by albet_januar
thx for your addition, but my program still wrong..
it takes TLE..

i am really confused bout this problem..

Posted: Fri Jun 30, 2006 10:12 pm
by jan_holmes
Remember, the length of one line string might be as long as 2000000 characters(might be less than 2000000 characters). I think you can not iterate each character like that... You should use another method... :wink:

Posted: Sat Jul 01, 2006 4:33 am
by chunyi81
The posted code above is fine. My AC code uses a char array of 1200000 characters and iterates through each character. However, check this:

Code: Select all

     for(i=0;i<strlen(kata);i++) 
You are calling strlen for each iteration of the loop. Of course you will get TLE this way. Try something like this:

Code: Select all

int len = strlen(kata);
for (i = 0;i < len;i++)

Posted: Sat Jul 01, 2006 8:20 pm
by albet_januar
thx for the reply..
i still cannot acc this problem..

492 PE...lol

Posted: Sat Nov 11, 2006 5:01 am
by subzero
Hi everyone... I got PE in this problem: "Pig Latin", I have no idea where is the bug... do you have any idea?

Code: Select all

#include <stdio.h>

int main() {
	char c;
	int b1,b2,b3;
	b1=b2=0;
	do {
        c=getchar();
        b3=((c>='A' && c<='Z') || (c>='a' && c<='z'));
		if (b1==0 && b3==1) { 
			if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U'){
				b2=-1;
				printf("%c",c);
			}else 
				b2=c;
			b1=1;

		}else {
		    if(b3==0){
		          if(b2>0) printf("%cay",b2);
		          else if (b2==-1) printf("ay");
           		  b1=b2=0;
			}
			printf("%c",c);
		}
	}while(c!=EOF);
	return 0;
}
thanks in advance

Posted: Sat Nov 11, 2006 3:51 pm
by sakhassan
I think u r also processing EOF .... which prints a space after the last input ...

u can try like this

do{

c = getchar();
if(c==EOF)
break;
....
....

}while(1);



Posted: Sat Nov 11, 2006 10:30 pm
by subzero
Yes!!... that was the problem...

I didn't think printing an EOF will output an space... lol

Thanks!!

Posted: Sun Nov 12, 2006 7:18 pm
by ALEXANDRIA_2
hi albet
I thought u miss this one

Code: Select all

3. Do not change the case of any letter. 
try these:

Code: Select all

input:
alex
Alex

Code: Select all

output:
alexay
Alexay
hope u get AC soon :D

492 - Why WA???

Posted: Mon Nov 27, 2006 5:11 am
by razor_red
I've got WA from this code, anyone can help me??

Code: Select all

/* got ACC  */

Posted: Mon Nov 27, 2006 8:22 am
by Jan
Dont open a new thread if there is one already. Try to search other threads(for same problem) first.

Why am i getting TLE?

Posted: Fri Dec 22, 2006 5:05 pm
by vijay03

Code: Select all


cut

I have not used calls to functions like strcat and i used strlen only minimally. Is the method i`m using too slow?

Posted: Fri Dec 22, 2006 11:36 pm
by Jan
In the vstrcat function you are finding the length of p[]. So, for each call you are calculating the length of b (since you are passing b). Just add one extra parameter (length of b) in that function.

Hope it helps.