Page 2 of 15
Hellooo...?!!
Posted: Mon Feb 17, 2003 10:49 am
by Hunter
Helloooo...??!
I'm sure it's an easy one 4 u, guys...!!

Posted: Mon Feb 17, 2003 8:08 pm
by little joey
Well, it's my personal opinion, but I don't like the idea of people just dumping their code on the board and expect others to do the debugging for them. I got lots of WA's myself and have my hands full debugging my own code. One way to get useful advise, is to tell people what you've already considered yourself, where you think the tricky parts of the input are, etc. But, again, that's my opinion.
You get an "Invalid Memory Reference" which almost always means that your array(s) are too small. I changed the array size from 100000 to 1000000 in your code, submitted it, and got "Wrong Answer". This means the array size is correct now (probably a bit too large, but who cares), but the output it produced is incorrect.
The problem description defines a word as a sequence of consecutive letters, and also tells you to leave the non-words alone. I tried the following input to your program:
Code: Select all
fourteen (14) little mice whent up 1 clock *&^&*
(there are three spaces at the end of the sentence!) and it produced:
Code: Select all
ourteenfay 14)(ay ittlelay icemay hentway upay 1ay lockcay &^&**ay ay ay y
Compare this to the output of my accepted program:
Code: Select all
ourteenfay (14) ittlelay icemay hentway upay 1 lockcay *&^&*
(there are still 3 spaces at the end).
Happy hunting!
-little joey
Define the WORDS
Posted: Tue Feb 18, 2003 1:55 am
by razibcse
hi,
I also came through lots of RTEs to get AC.
u should first make the array size 1,000000...
then separate the words & non-words...
words r those which r made of only alpha characters...
non-words mean space & other characters...
then modify each word & print the non-words as they r...
wish u good luck...
Razib
492 - Pig Latin
Posted: Thu Feb 20, 2003 4:15 pm
by Sajid
I got WA with my code.. i dont know why.....
the output is ok , i think. But, i think.. the only problem with to scan a number frm the user or.. for the newline at the end of each output.
In the previous post of this board I found ,, to use scanf("%s",input) .... istead of gets(input),, but why??????????
if i use gets then, what is the problem? and if i use scanf then how can make a new line at the end of each output..
I hope, u'll try to help me.
Posted: Thu Feb 20, 2003 8:00 pm
by little joey
to razibcse: having fun rephrasing my reply? Or do I hear an echo...
Posted: Fri Feb 21, 2003 2:58 am
by turuthok
I don't think you can use scanf("%s") here since I'm sure "%s" format ignores white-space ...
My slow but AC-ed Java program reads the input one character at a time and maintains a simple state throughout the runtime.
-turuthok-
About the critical input
Posted: Fri Feb 21, 2003 6:01 am
by Sajid
Thanx so much for ur help. now I m using gets() function... but still wrong answer...
can u tell me some critical input and output?????
c ya ....
Re: Define the WORDS
Posted: Fri Feb 21, 2003 9:41 pm
by Sajid
razibcse wrote:
u should first make the array size 1,000000...
Is it ANSI C Standard?
Yet Not AC
Posted: Sat Feb 22, 2003 9:07 am
by Hunter
Hmmm... I've matched those all, but got TLE.
Seems my algo's quite silly, eh? Nevermind, I'll fix it later..
Thx anyway...
P492! Why WA.....? Please HELP!
Posted: Sat Feb 22, 2003 11:27 am
by adikhosla
As far as I know this is a very easy problem, and an even easier problem for all of you out there. Please help me find out what is wrong. Please provide some sample inputs and outputs. I have also read past discussions about this question and rectified any problems but I still get WA no matter what.
Thanks a lot for your help!!!
[c]#include <stdio.h>
#include <string.h>
#include <ctype.h>
long temp, curr=0, temp2, start, x, end, y;
char line[1000000], currword[1000000];
int main(void)
{
while(gets(line)!='\0')
{
start=0;
curr=0;
x=0; y=(long)(strlen(line));
while(x<y)
{
if(!isalpha(line[x])) printf("%c", line[x]);
else break;
end=x;
x++;
}
temp2=0;
for(temp=x; temp<y; temp++)
{
if(isalpha(line[temp]))
{
if(curr==0) if(temp!=0) start=temp-1;
currword[temp2]=line[temp];
temp2++;
curr=1;
end=temp;
}
else
{
if(curr==1)
{
if(currword[0]== 'a' || currword[0]== 'A' || currword[0]== 'e' || currword[0]== 'E' || currword[0]== 'i' || currword[0]== 'I' || currword[0]== 'o' || currword[0]== 'O' || currword[0]== 'u' || currword[0]== 'U')
{
for(x=0; x<temp2; x++) printf("%c", currword[x]);
printf("ay");
while(temp<y)
{
if(!(isalpha(line[temp]))) printf("%c", line[temp]);
else
{
temp--;
break;
}
temp++;
}
}
else
{
for(x=1; x<temp2; x++) printf("%c", currword[x]);
printf("%c", currword[0]);
printf("ay");
while(temp<y)
{
if(!(isalpha(line[temp]))) printf("%c", line[temp]);
else
{
temp--;
break;
}
temp++;
}
}
temp2=0;
}
curr=0;
}
if(curr==1 && temp==y-1)
{
if(currword[0]== 'a' || currword[0]== 'A' || currword[0]== 'e' || currword[0]== 'E' || currword[0]== 'i' || currword[0]== 'I' || currword[0]== 'o' || currword[0]== 'O' || currword[0]== 'u' || currword[0]== 'U')
{
for(x=0; x<temp2; x++) printf("%c", currword[x]);
printf("ay");
for(x=end+1; x<=temp; x++) printf("%c", line[x]);
}
else
{
for(x=1; x<temp2; x++) printf("%c", currword[x]);
printf("%c", currword[0]);
printf("ay");
for(x=end+1; x<=temp; x++) printf("%c", line[x]);
}
temp2=0;
}
}
printf("\n");
}
return 0;
}[/c]
-Aditya
Posted: Sat Feb 22, 2003 10:54 pm
by turuthok
To Hunter:
There is one way to improve the speed by quite a bit. I noticed when you try to process a word that starts with non-vowel, you did some kind of a ROTATE-LEFT operation to your string which can be expensive on long words.
You might want to think of something that avoids ROTATE-LEFT like you did. Probably something like printing the word starting at the second character followed by printing the first character + "ay" ... That way you don't have the unnecessary (time-wasting) operations.
Another very-little-and-tiny improvement is your [c]printf("%s", word);[/c] ... Since your word doesn't have any format string ... I think it's better to just plainly write [c]printf(word);[/c] ... This way the printf() function doesn't have to parse the "%" ... hehehe, but again, this is very very minor, it probably doesn't matter at all.
Anyway, ... good luck.
-turuthok-
Posted: Sat Feb 22, 2003 11:07 pm
by turuthok
What if a word starts with a digit (instead of an alphabet) ... In this case you would print that digit which is already wrong.
And also, I wonder if one line can have more than 10,000 chars that you allocated.
FYI: I grabbed your code and ran it against the sample-input. It crashed. Please make sure you test the code first.
-turuthok-
Posted: Sat Feb 22, 2003 11:22 pm
by Sajid
To turuthok,
As for Inforation, u can also use scanf() function as like the following
[c]
while(scanf("%s%c",a,&ch)==2)
.
.
.
.
printf("%s%c",a,ch);[/c]
get it??
Can anyone tell me the critical inputs for this problem???
Posted: Sat Feb 22, 2003 11:31 pm
by turuthok
Hello Sajid, ... I see ... I never used scanf("%s%c", ...) function like you described ... Will it work if I have an input like this: "abcde fghij" ?
I'm sure it's a little bit confusing coding it using while(scanf("%s%c", ...) == 2) ... Or I'm just too skeptical about that ...
I didn't try your method though ... I should.
-turuthok-
Posted: Sat Feb 22, 2003 11:33 pm
by turuthok
Oops, I didn't realize multiple blanks will be truncated ... sorry.
Sajid, the input I mentioned above should be:
-turuthok-
[/code]