Page 3 of 15
Posted: Sat Feb 22, 2003 11:40 pm
by Sajid
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???
Posted: Sun Feb 23, 2003 1:10 am
by turuthok
Sajid, forgive me ... but I still cannot see how you handle multiple spaces between words using your method of "%s%c" stuff ...
If it works, ... I'm happy for you
Regards,
-turuthok-
Posted: Sun Feb 23, 2003 7:03 am
by Sajid
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.......................
Posted: Sun Feb 23, 2003 6:31 pm
by Hunter
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]
Posted: Sun Feb 23, 2003 8:43 pm
by Sajid
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??? 
about inputing a line
Posted: Mon Feb 24, 2003 4:54 am
by Nick
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 :
Input :
What if the input is more than one line?
Like this sample
Using your module.... string a will contain "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
sorry
Posted: Mon Feb 24, 2003 8:59 am
by Sajid
To Nick,
Yes.. i m so sorry that my code has some bugs which i overlooked...
thanx nick.. 
Posted: Mon Feb 24, 2003 9:02 am
by Sajid
turuthok wrote:Sajid, the input I mentioned above should be:
-turuthok-
Turuthok,sorry, my code will not work with the above input..
sorry for that....
--- Sajid
Posted: Mon Feb 24, 2003 11:07 am
by turuthok
Sajid, don't worry about it ...
I hope you'll get this problem AC-ed soon ...
-turuthok-
Posted: Mon Feb 24, 2003 11:25 am
by turuthok
Hunter, ... try this input:
-turuthok-
Posted: Mon Feb 24, 2003 1:26 pm
by adikhosla
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?
(non-words should be output exactly as they appear in the input):
Thanks for replying,
Aditya
Posted: Thu Feb 27, 2003 5:31 pm
by Hunter
I don't understand..! Shouldn't it result:
Posted: Fri Feb 28, 2003 11:05 am
by razibcse
To Sajid:
Of course, it's ANSI standard...
in many problems, you will get RTE if you use smaller array
Razib
Posted: Mon Mar 03, 2003 4:01 pm
by Hunter
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:
Code: Select all
a1
a.a.a.
a.a...
a1.
.a1?
1a...a
p..p
What they should result?
Do the "consecutive sequence of letters (upper and/or lower case)" takes alpha
NUMERIC characters?
Hunting 4 answers,
Hunter
thanx all
Posted: Wed Mar 05, 2003 9:54 pm
by Sajid
at last i got AC ...
thanx to all.. specially Turuthok.
c ya ... 