492 - Pig-Latin
Moderator: Board moderators
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
Hello turuthok,
i failed to describe it,,
i meant, instead of this code:[c]while(gets(a))
{
...
...
.....printf("%c",a);
}
printf("\n");
[/c]
we can also use this...[c]while(scanf("%s%c",a,&ch)==2)
{
...
...
...
.....prinft("%c",a);
}
printf("%c",&ch);[/c]
is it clear now???
i failed to describe it,,
i meant, instead of this code:[c]while(gets(a))
{
...
...
.....printf("%c",a);
}
printf("\n");
[/c]
we can also use this...[c]while(scanf("%s%c",a,&ch)==2)
{
...
...
...
.....prinft("%c",a);
}
printf("%c",&ch);[/c]
is it clear now???
Sajid Online: www.sajidonline.com
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
turuthok, look ...
[c]while(scanf("%s%c",a,&ch)==2)
{
}
[/c]
here, the single word is stroed in a[] and the next non-alphabet(digit, space, newline etc.) is stored in ch.
and u can do the loop word by word and after completing each loop, jst print the ch variable.. which stored a non-alphabetic chanracter..
and that's it... It works in my program.It's cute technic, isn't it?
But my program still WA.......................
[c]while(scanf("%s%c",a,&ch)==2)
{
}
[/c]
here, the single word is stroed in a[] and the next non-alphabet(digit, space, newline etc.) is stored in ch.
and u can do the loop word by word and after completing each loop, jst print the ch variable.. which stored a non-alphabetic chanracter..
and that's it... It works in my program.It's cute technic, isn't it?

But my program still WA.......................
Sajid Online: www.sajidonline.com
It's my best, baby! Yet not AC... This time a <0.353 sec> WA.
More trick(s) missed?
[cpp]#include <stdio.h>
#include <string.h>
char str[1000000],word[1000000];
long len,i,j,k;
void main ()
{
while (gets(str))
{
len=strlen(str); j=-1;
for (i=0;i<=len;i++)
{
if ((str>=65 && str<=90) || (str>=97 && str<=122)) {j++; word[j]=str;}
else
{
if ((str[i-1]>=65 && str[i-1]<=90) || (str[i-1]>=97 && str[i-1]<=122))
{
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 (k=1;k<=j;k++)
{
printf ("%c",word[k]);
}
printf ("%cay",word[0]);
}
for (k=0;k<=j;k++)
{
word[k]='\0';
}
j=-1;
}
if (str!='\0') printf ("%c",str);
}
}
printf ("\n");
}
}[/cpp]
More trick(s) missed?
[cpp]#include <stdio.h>
#include <string.h>
char str[1000000],word[1000000];
long len,i,j,k;
void main ()
{
while (gets(str))
{
len=strlen(str); j=-1;
for (i=0;i<=len;i++)
{
if ((str>=65 && str<=90) || (str>=97 && str<=122)) {j++; word[j]=str;}
else
{
if ((str[i-1]>=65 && str[i-1]<=90) || (str[i-1]>=97 && str[i-1]<=122))
{
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 (k=1;k<=j;k++)
{
printf ("%c",word[k]);
}
printf ("%cay",word[0]);
}
for (k=0;k<=j;k++)
{
word[k]='\0';
}
j=-1;
}
if (str!='\0') printf ("%c",str);
}
}
printf ("\n");
}
}[/cpp]
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
I think, u still cant get..
ok, lets compare the following two almost the same programs.
Using gets()...
[c]char a[100];
int i;
while(gets(a))
{
for(i=0;a;i++) printf("%c",a);
printf("\n");
}[/c]
Using scanf()...
[c]char a[100],ch;
int i;
while(scanf("%s%c",a,&ch)==2)
{
for(i=0;a;i++) printf("%c",a);
printf("%c",ch);
}[/c]
Get it now???
ok, lets compare the following two almost the same programs.
Using gets()...
[c]char a[100];
int i;
while(gets(a))
{
for(i=0;a;i++) printf("%c",a);
printf("\n");
}[/c]
Using scanf()...
[c]char a[100],ch;
int i;
while(scanf("%s%c",a,&ch)==2)
{
for(i=0;a;i++) printf("%c",a);
printf("%c",ch);
}[/c]
Get it now???

Sajid Online: www.sajidonline.com
about inputing a line
To Sajid,
your code
it has a bug.....since scanf ignores white spaces....your module wont stop until it reached end of file.
Meanwhile, gets function stops when it encounters '\n' or carriage return '\r'. So....your code cannot get one line at a time. Ex :
But using gets function, a contain "What if the input is more than one line?"
Then....the program starts to process the string to get the proper output
before gets another line.
Hope i'm right,
Nick
your code
Code: Select all
while(scanf("%s%c",a,&ch)==2)
{
}
Meanwhile, gets function stops when it encounters '\n' or carriage return '\r'. So....your code cannot get one line at a time. Ex :
Using your module.... string a will contain "sample".Input :
What if the input is more than one line?
Like this sample
But using gets function, a contain "What if the input is more than one line?"
Then....the program starts to process the string to get the proper output
before gets another line.
Hope i'm right,
Nick
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
sorry
To Nick,
Yes.. i m so sorry that my code has some bugs which i overlooked...
thanx nick..
Yes.. i m so sorry that my code has some bugs which i overlooked...
thanx nick..

Sajid Online: www.sajidonline.com
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
Turuthok,sorry, my code will not work with the above input..turuthok wrote:Sajid, the input I mentioned above should be:-turuthok-Code: Select all
abcde fghij
sorry for that....
--- Sajid
Sajid Online: www.sajidonline.com
-
- Experienced poster
- Posts: 193
- Joined: Thu Sep 19, 2002 6:39 am
- Location: Indonesia
- Contact:
Hunter, ... try this input:
-turuthok-
Code: Select all
abc123def
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
I have tested and tried the code. It does work. Maybe its the compiler that you are using to compile it. I am using Microsoft Visual C++ .NET. When I submit this code to the online judge I get a WA, when I change the array length to 1000000 and not a TLE or RTE, which might suggest what you are saying. I am sorry for writing the wrong array length. Just for clarification, arent you supposed to print out the digits or any other characters before and after the words?
Aditya
Thanks for replying,(non-words should be output exactly as they appear in the input):
Aditya
I don't understand..! Shouldn't it result:
Code: Select all
abcay123efday
I don't like this!!! This prob. keeps me WA for weeks...!!
I've handled the "abc123def" input to result "abc123defay". Is it correct?!
Few I/O cases follow up:
What they should result?
Do the "consecutive sequence of letters (upper and/or lower case)" takes alphaNUMERIC characters?
Hunting 4 answers,
Hunter
I've handled the "abc123def" input to result "abc123defay". Is it correct?!
Few I/O cases follow up:
Code: Select all
a1
a.a.a.
a.a...
a1.
.a1?
1a...a
p..p
Do the "consecutive sequence of letters (upper and/or lower case)" takes alphaNUMERIC characters?
Hunting 4 answers,
Hunter
-
- Learning poster
- Posts: 94
- Joined: Sat Oct 05, 2002 5:34 pm
- Location: CS - AIUB, Dhaka, Bangladesh.
- Contact:
thanx all
at last i got AC ...
thanx to all.. specially Turuthok.
c ya ...

thanx to all.. specially Turuthok.
c ya ...

Sajid Online: www.sajidonline.com