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

Hunter
New poster
Posts: 9
Joined: Wed Feb 12, 2003 10:50 am
Location: Alaska

Hellooo...?!!

Post by Hunter »

Helloooo...??!
I'm sure it's an easy one 4 u, guys...!! :D
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post 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
razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Location: SUST,BANGLADESH
Contact:

Define the WORDS

Post 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
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

492 - Pig Latin

Post 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.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

to razibcse: having fun rephrasing my reply? Or do I hear an echo...
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post 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-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

About the critical input

Post 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 ....
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

Re: Define the WORDS

Post by Sajid »

razibcse wrote:
u should first make the array size 1,000000...
Is it ANSI C Standard?
Sajid Online: www.sajidonline.com
Hunter
New poster
Posts: 9
Joined: Wed Feb 12, 2003 10:50 am
Location: Alaska

Yet Not AC

Post 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...
adikhosla
New poster
Posts: 3
Joined: Fri Feb 14, 2003 3:12 pm

P492! Why WA.....? Please HELP!

Post 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
Last edited by adikhosla on Mon Feb 24, 2003 1:27 pm, edited 1 time in total.
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post 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-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post 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-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

Post 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???
Sajid Online: www.sajidonline.com
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post 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-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

Oops, I didn't realize multiple blanks will be truncated ... sorry.
Sajid, the input I mentioned above should be:

Code: Select all

abcde    fghij
-turuthok-
[/code]
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
Post Reply

Return to “Volume 4 (400-499)”