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

Zaspire
New poster
Posts: 36
Joined: Sun Apr 23, 2006 2:42 pm
Location: Russia

Post by Zaspire »

I compile my solutions by Dev-C++4.9.9.2 before submiting. It help but not always :evil: .
albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

492 Pig Latin - RE

Post 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");
	}



}
jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post 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:
albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar »

thx for your addition, but my program still wrong..
it takes TLE..

i am really confused bout this problem..
jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post 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:
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post 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++)
albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar »

thx for the reply..
i still cannot acc this problem..
subzero
New poster
Posts: 26
Joined: Mon Aug 15, 2005 5:21 am

492 PE...lol

Post 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
There is no knowledge that is no power.
sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post 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);


subzero
New poster
Posts: 26
Joined: Mon Aug 15, 2005 5:21 am

Post by subzero »

Yes!!... that was the problem...

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

Thanks!!
There is no knowledge that is no power.
ALEXANDRIA_2
New poster
Posts: 10
Joined: Tue Nov 07, 2006 2:03 pm
Location: Jakarta

Post 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
Impossible is nothing
razor_red
New poster
Posts: 2
Joined: Mon Nov 27, 2006 4:56 am
Location: Indonesia

492 - Why WA???

Post by razor_red »

I've got WA from this code, anyone can help me??

Code: Select all

/* got ACC  */
Last edited by razor_red on Tue Dec 19, 2006 4:51 am, edited 1 time in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Dont open a new thread if there is one already. Try to search other threads(for same problem) first.
Ami ekhono shopno dekhi...
HomePage
vijay03
New poster
Posts: 33
Joined: Wed Sep 13, 2006 6:46 pm
Contact:

Why am i getting TLE?

Post 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?
Last edited by vijay03 on Tue Dec 26, 2006 8:59 pm, edited 1 time in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
Post Reply

Return to “Volume 4 (400-499)”