Page 10 of 15
Posted: Wed Aug 01, 2007 12:00 am
by mf
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
!= 0.
Posted: Wed Aug 01, 2007 6:28 am
by Fuad Hassan EWU

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.
Posted: Fri Nov 30, 2007 5:11 pm
by sumonSUST
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.
Posted: Fri Nov 30, 2007 7:45 pm
by Jan
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.
Posted: Wed Dec 19, 2007 7:49 pm
by yangmie
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..
Posted: Thu Dec 20, 2007 11:42 am
by Jan
Save your output to a file. You are printing the terminating NULL character, too.
Posted: Sun Feb 10, 2008 1:10 pm
by AcmNightivy
i got WA,RE,TLE for three simple problems for more than one page..my god..And now i can't find my mistakes in this problem..All the cases I found run correctly..Help..
Code: Select all
#include <stdio.h>
int main ()
{
char str[12000];
char word[10000];
int i, j;
int current;
while (gets (str))
{
current = 0;
while (str[current] >= 'z' || str[current] <= 'A')
{
if (str[current] == '\0')
{
break;
}
printf ("%c", str[current++]);
}
if (str[current] == '\0')
{
printf ("\n");
continue;
}
while (true)
{
j = 0;
while (str[current] <= 'z' && str[current] >= 'A')
{
word[j++] = str[current++];
}
word[j] = '\0';
if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u'
|| word[0] == 'A' || word[0] == 'E' || word[0] == 'I' || word[0] == 'O' || word[0] == 'U')
printf ("%say", word);
else
{
for (i = 1; word[i] != '\0'; i++)
printf ("%c", word[i]);
printf ("%cay", word[0]);
}
while (str[current] <= 'A' || str[current] >= 'z')
{
if (str[current] == '\0')
break;
printf ("%c", str[current]);
current++;
}
if (str[current] == '\0')
{
printf ("\n");
break;
}
}
}
return 0;
}
Posted: Wed Feb 27, 2008 9:44 pm
by turcse143
u don't take input into array. it cause TLE.
instead of it,u can take input by
then arrange ur code
hope all the error will solved
Posted: Thu Feb 28, 2008 4:26 pm
by AcmNightivy
turcse143 wrote:
u don't take input into array. it cause TLE.
instead of it,u can take input by
then arrange ur code
hope all the error will solved
why i can't using gets()?Thanks~
492 :: WA Wa help about Wa why?
Posted: Tue May 06, 2008 6:30 am
by rajib_cse_sust
Code: Select all
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 10000000
char str[MAX];
int isvowel(char latter);
int main()
{
long i, len, flag;
char temp;
// freopen("E:\\nikson\\in.txt","r",stdin);
while( gets(str) )
{
len = strlen( str );
for( i = 0; i < len; i++ )
{
if( isspace( str[i] ) || ispunct( str[i] ) ) printf("%c", str[i]);
else
{
flag = isvowel( str[i] );
if( flag )
{
while(1)
{
if( isspace( str[i] ) || ispunct( str[i] ) || ( i == len ) ) { --i; break; }
else printf("%c", str[ i++ ]);
}
printf("ay");
}
else
{
temp = str[ i++ ];
while( 1 )
{
if( isspace( str[i] ) || ispunct( str[i] ) || ( i == len ) ) { --i; break; }
else printf("%c", str[ i++ ]);
}
printf("%cay", temp);
}
}
}
if( str[len] != '\0')
printf("%c", str[len]);
}
return 0;
}
int isvowel(char latter)
{
if( latter == 'a' || latter == 'A') return 1;
else if( latter == 'e' || latter == 'E') return 1;
else if( latter == 'i' || latter == 'I') return 1;
else if( latter == 'o' || latter == 'O') return 1;
else if( latter == 'u' || latter == 'U') return 1;
else return 0;
}
Re: 492 :: WA Wa help about Wa why?
Posted: Tue May 06, 2008 6:55 am
by Jan
I have already told you to use existing thread.
Re: 492 WA: tell me why ........................
Posted: Thu May 08, 2008 5:41 pm
by amr saqr
"non-words should be output exactly as they appear in the input" & A word is defined as "a consecutive sequence of letters",
Simply, the previous line contains the tricks of this problem,
any character outside the range 'a'-'z' or the range 'A'-'Z' is a non-word,
manipulate words only

,
and here is some critical inputs/outpus 4 u,
input:
Code: Select all
This is the input.
He is a boy.
Object123oriented,..,.Programming
000000000
aaaaaaaaaaaa
Aaaaaaaaaaaa
computerprogrammingII
cse-1204 Computer programming II
ACM programming contest was held on 10th November, 2001 at BUET.
an a eye An A Eye Bee BEE Dhaka-1205 1st last.
output:
Code: Select all
hisTay isay hetay inputay.
eHay isay aay oybay.
Objectay123orienteday,..,.rogrammingPay
000000000
aaaaaaaaaaaaay
Aaaaaaaaaaaaay
omputerprogrammingIIcay
secay-1204 omputerCay rogrammingpay IIay
ACMay rogrammingpay ontestcay asway eldhay onay 10htay ovemberNay, 2001 atay UETBay.
anay aay eyeay Anay Aay Eyeay eeBay EEBay hakaDay-1205 1tsay astlay.
WA in 492. Why?
Posted: Wed Nov 12, 2008 7:23 am
by vinocit
Could any one say whats wrong in my code i am getting WA
Code: Select all
#include<iostream>
using namespace std;
int isvowel(char c)
{
switch(c)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
return 1;
}
return 0;
}
int main()
{
char s[1000];
int n=0;
while(cin.getline(s,1000))
{
int l=strlen(s);
int pos=0;
if(n)cout<<"\n";
n++;
while(s[pos]!=0)
{
char start=0;
while(!((s[pos]>='a'&&s[pos]<='z')||(s[pos]>='A'&&s[pos]<='Z')||pos>=l))
{
cout<<s[pos];
pos++;
}
if(s[pos]==0)break;
if(!(isvowel(s[pos])))
{
start=s[pos];
pos++;
}
while(((s[pos]>='a'&&s[pos]<='z')||(s[pos]>='A'&&s[pos]<='Z'))&&pos<l)
{
cout<<s[pos];
pos++;
}
if(start)cout<<start;
cout<<"ay";
}
}
return 0;
}
Re: 492 WA: tell me why ........................
Posted: Sat Nov 15, 2008 12:25 pm
by vinocit
Could any one say wats wrong with my code. My code gives correct output with the above input
Code: Select all
#include<iostream>
using namespace std;
int isvowel(char c)
{
switch(c)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
return 1;
}
return 0;
}
int main()
{
char s[1000];
int n=0;
while(cin.getline(s,1000))
{
int l=strlen(s);
int pos=0;
n++;
while(s[pos]!=0)
{
char start=0;
while(!((s[pos]>='a'&&s[pos]<='z')||(s[pos]>='A'&&s[pos]<='Z')||pos>=l))
{
cout<<s[pos];
pos++;
}
if(s[pos]==0)break;
if(!(isvowel(s[pos])))
{
start=s[pos];
pos++;
}
while(((s[pos]>='a'&&s[pos]<='z')||(s[pos]>='A'&&s[pos]<='Z'))&&pos<l)
{
cout<<s[pos];
pos++;
}
if(start)cout<<start;
cout<<"ay";
}
cout<<"\n";
}
return 0;
}
Re: Time Limit Exceeded in 492. Why?
Posted: Sun Nov 23, 2008 12:14 pm
by gba356
You should print '\n' after each line.
Also I'm not sure if a buffer with a size of 1000 would be enough..