
492 - Pig-Latin
Moderator: Board moderators
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
492 Pig Latin - RE
can someone help me for this problem??
i don't know why my solution got RE
this is my code
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");
}
}
-
- Experienced poster
- Posts: 136
- Joined: Fri Apr 15, 2005 3:47 pm
- Location: Singapore
- Contact:
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
-
- Experienced poster
- Posts: 136
- Joined: Fri Apr 15, 2005 3:47 pm
- Location: Singapore
- Contact:
The posted code above is fine. My AC code uses a char array of 1200000 characters and iterates through each character. However, check this:
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
for(i=0;i<strlen(kata);i++)
Code: Select all
int len = strlen(kata);
for (i = 0;i < len;i++)
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
492 PE...lol
Hi everyone... I got PE in this problem: "Pig Latin", I have no idea where is the bug... do you have any idea?
thanks in advance
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;
}
There is no knowledge that is no power.
-
- New poster
- Posts: 10
- Joined: Tue Nov 07, 2006 2:03 pm
- Location: Jakarta
hi albet
I thought u miss this one
try these:
hope u get AC soon 
I thought u miss this one
Code: Select all
3. Do not change the case of any letter.
Code: Select all
input:
alex
Alex
Code: Select all
output:
alexay
Alexay

Impossible is nothing
492 - Why WA???
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.
Dont open a new thread if there is one already. Try to search other threads(for same problem) first.
Ami ekhono shopno dekhi...
HomePage
HomePage
Why am i getting TLE?
Code: Select all
cut
Last edited by vijay03 on Tue Dec 26, 2006 8:59 pm, edited 1 time in total.
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.
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
HomePage