why WA?(492)piglatin

All about problems in Volume IV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

why WA?(492)piglatin

Postby ishtiaq ahmed » Wed Jan 31, 2007 3:26 pm

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.
ishtiaq ahmed
Learning poster
 
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

Postby helloneo » Wed Jan 31, 2007 3:38 pm

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..
helloneo
Guru
 
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Postby Debashis Maitra » Wed Jan 31, 2007 9:44 pm

Dear istiaq you have opened a lot of new threads
you shouldn't do that

and please send your code using code tag
Akash chhoyar swopno
Dream to touch the sky
User avatar
Debashis Maitra
Learning poster
 
Posts: 62
Joined: Sun Jul 09, 2006 8:31 am
Location: University of Dhaka

492 TLE,help needed

Postby Fuad Hassan EWU » Tue Jul 31, 2007 11:47 pm

:oops:
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
User avatar
Fuad Hassan EWU
New poster
 
Posts: 38
Joined: Tue Jul 17, 2007 3:21 pm
Location: East West University

Postby mf » Wed Aug 01, 2007 12:00 am

for(i=0;i<=strlen(str);i++)

The check "i<=strlen(str)" in this part of your code is done at each loop iteration, and every time strlen() is recomputed again and again, resulting in quadratic runtime.

Get rid of strlen() in the loop condition, e.g. by computing strlen() just once, before the loop begins, or checking that str[i] != 0.
mf
Guru
 
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland

Postby Fuad Hassan EWU » Wed Aug 01, 2007 6:28 am

:D thanks mf. i got AC after having you as help line.

after changing my code according to your direction i was getting RTE.
then making the arrays static i got AC.

thanks.
Eagle er moto daana meley urbo
User avatar
Fuad Hassan EWU
New poster
 
Posts: 38
Joined: Tue Jul 17, 2007 3:21 pm
Location: East West University

Postby sumonSUST » Fri Nov 30, 2007 5:11 pm

Code: Select all

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define SI 1000009

char line[SI];

int main()
{
   
   long i,j,k,len;

    while(gets(line)) 
   {
      len=strlen(line);
      
      for(i=0;i<len;i++)
      {
         if(toupper(line[i])>='A' && toupper(line[i])<='Z')
         {
            if(toupper(line[i])=='A'||toupper(line[i])=='E'||toupper(line[i])=='I'||toupper(line[i])=='O'||toupper(line[i])=='U')
            {
               while(line[i]!=' ' && i<len)
               {
                  if(toupper(line[i])>='A' && toupper(line[i])<='Z')
                  {
                     printf("%c",line[i]);
                  }
                  else
                  {
                     break;
                  }
                  i++;
               }
               printf("%s%c","ay",line[i]);
            }
            else
            {
               j=i;
               
               while(line[++i]!=' ' && i<len)
               {
                  if(toupper(line[i])>='A' && toupper(line[i])<='Z')
                     printf("%c",line[i]);
                  else
                  {
                     break;
                  }
                  
               }
               printf("%c%s%c",line[j],"ay",line[i]);
            }
         }
         else
            printf("%c",line[i]);
      }
      printf("\n");
   }      
   
   
   return 0;
}


i get runtime error
plz help me.
sumonSUST
New poster
 
Posts: 5
Joined: Fri Oct 26, 2007 3:55 pm

Postby Jan » Fri Nov 30, 2007 7:45 pm

I don't know why you are getting RTE but I think your code is not correct. Suppose the input is only 'b'. Your code prints the null character, too. Save your output in a file. Then check it.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby yangmie » Wed Dec 19, 2007 7:49 pm

Code: Select all
#include<stdio.h>
#include<ctype.h>
char input[1000000];
char temp[1000000];
int main()
{
        while(gets(input)!=NULL)
        {
                int i=0;
                while(input[i]!='\0')
                {
                        int x=0;
                        while(isalpha(input[i]))
                        {
                                temp[x]=input[i];
                                x++;
                                i++;
                        }
                        int y;
                        if(temp[0]=='a'||temp[0]=='e'||temp[0]=='i'||temp[0]=='o'||temp[0]=='u'||temp[0]=='A'||temp[0]=='E'||temp[0]=='I'||temp[0]=='O'||temp[0]=='U')
                        {
                                for(y=0;y<x;y++)
                                        printf("%c",temp[y]);
                                printf("ay");
                        }
                        else if(isalpha(temp[0]))
                        {
                                for(y=1;y<x;y++)
                                        printf("%c",temp[y]);
                                printf("%cay",temp[0]);

                        }
                        printf("%c",input[i]);
                        i++;
                        temp[0]='\0';
                }
                printf("\n");
                int k=0;
                while(input[k]!='\0')
                {
                        input[k]='\0';
                        k++;
                }
        }
        return 0;
}


why wa.....

[Edited by : Jan] Use code tags..
yangmie
New poster
 
Posts: 3
Joined: Fri Nov 30, 2007 12:14 pm

Postby Jan » Thu Dec 20, 2007 11:42 am

Save your output to a file. You are printing the terminating NULL character, too.
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Why RTE >> Piglatin 492

Postby george3456 » Fri Oct 23, 2009 1:01 am

don't know why getting RTE..... help plzzzzzzzzzzz
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{
   char s[300000],t[300000];
   char temp;

   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);

   while(gets(s))
   {
      long i,len;

      len = strlen(s);
      //printf("%d",len);

      for(i = 0;i<len;)
      {
         if(isalpha(s[i]))
         {
            if((s[i]!='a')&&(s[i]!='e')&&(s[i]!='i')&&(s[i]!='o')&&(s[i]!='u')&&
               (s[i]!='A')&&(s[i]!='E')&&(s[i]!='I')&&(s[i]!='O')&&(s[i]!='U'))
            {
               temp = s[i++];
            }
            while(isalpha(s[i]))
               printf("%c",s[i++]);
            t[0] = temp;
            t[1] = '\0';
            strcat(t,"ay");
            printf("%s",t);
            temp = '\0';
         }
         if(!isalpha(s[i]))
         {
            //flag = 0;
            printf("%c",s[i++]);
         }
      }
   printf("\n");
   }

   
   return 0;
}   
The most important thing is never stop questioning ~ Albert Einstein
george3456
New poster
 
Posts: 5
Joined: Tue Sep 15, 2009 11:16 am

Re: Why RTE >> Piglatin 492

Postby jhosimar3001 » Fri May 14, 2010 4:27 am

george3456 wrote:don't know why getting RTE..... help plzzzzzzzzzzz

Hi for this problem you don't have to use gets() or scanf() the reason is, the input text is too big to store in any an array we plan/guess to declare, whether it is 1 million or 10 million elements!! so, get the input as character by character... you can use while(c=getchar()) and to finish if(c==EOF) return 0; otherwise check if is a letter or not and continue with the code...
jhosimar3001
New poster
 
Posts: 3
Joined: Sun Mar 07, 2010 1:56 am

Re: why WA?(492)piglatin

Postby obbY » Sun May 16, 2010 11:45 pm

Hi everyone, for those who get RTE, I got ACC by using a char array of 10000000 and fgets() for taking input
obbY
New poster
 
Posts: 5
Joined: Sun May 16, 2010 11:41 pm

why WA?(492)piglatin

Postby sonjbond » Mon Jul 09, 2012 4:48 am

my input output is pk ... bt y i am getting WA ??? plz help me ,,,, i m trying it from last 5 days but cant ,,,,, :( plz help ,,,
here's my code :

#include<stdio.h>
#include<string.h>
int main()
{
char str[1000000],wrd[1000000];
int len,n,i,j,k,l,m;
while(gets(str))
{
len=strlen(str);
m=0;
for(i=0; i<len+1; i++)
{
if((str[i]>=65&&str[i]<=90)||(str[i]>=97&&str[i]<=122))
{
wrd[m]=str[i];
m++;
}
else
{
if(wrd[0]=='A'||wrd[0]=='E'||wrd[0]=='I'||wrd[0]=='O'||wrd[0]=='U'||wrd[0]=='a'||wrd[0]=='e'||wrd[0]=='i'||wrd[0]=='o'||wrd[0]=='u')
{
for(j=0; j<=m-1; j++)
printf("%c",wrd[j]);
if(m!=0)
printf("ay");
}
else
{
if(m>1)
for(j=1; j<=m-1; j++)
printf("%c",wrd[j]);
if(m>=1)
printf("%c",wrd[0]);
if(m!=0)
printf("ay");
}
m=0;
printf("%c",str[i]);
}
}
printf("\n");
}
return 0;
}


plz heip me ,,,, plz ... i can not try another problem b4 getting AC in 492 ,,,,,,,,,,, plz help me....
sonjbond
New poster
 
Posts: 18
Joined: Wed Jul 04, 2012 10:30 pm

Re: why WA?(492)piglatin

Postby sonjbond » Sun Jul 15, 2012 11:44 pm

plz help .... reply my post plz....
sonjbond
New poster
 
Posts: 18
Joined: Wed Jul 04, 2012 10:30 pm

Next

Return to Volume IV

Who is online

Users browsing this forum: Google [Bot] and 0 guests