Page 4 of 7

Posted: Fri Jul 16, 2004 2:56 pm
by afonsocsc
Hi,
In the manpage of puts:
"puts() writes the string s and a trailing newline to stdout."
You're putting a newline at the end of each line of the input, so you should use either fputs or printf...

Hope it helps!

Posted: Fri Jul 16, 2004 5:09 pm
by Guest
But in case of using printf, i would still have to put a newline after the string.. i think the prob is elsewhere.. :cry:
anyway, thank you for replying.

Posted: Fri Jul 16, 2004 5:51 pm
by afonsocsc
gets() also gets the newline from input, so if you use puts() it will have two newlines, if you want to use puts(), you simply have to remove the '\n' of the string retrieved by gets().

Posted: Sat Jul 17, 2004 10:06 am
by Guest
But my output format still looks correct. Perhaps you would like to compile and run it?

Posted: Sat Jul 17, 2004 12:06 pm
by afonsocsc
Ok, sorry, I was confusing gets() with fgets(), gets() doesn't put the newline in the string...
But I found a bug in the code, try this input:
999999999999999999 * 1

Posted: Sat Jul 17, 2004 8:21 pm
by Guest
Thank you so much for pointing out my mistake, :D
At last I've got accepted, :D

Thank you again!

Posted: Tue Aug 03, 2004 1:19 pm
by jackie
After many WAs i change the algorithm. Use double instead of big number.
and i get AC.
Then i find the judge's input doesn't contain line like
1000000*10000

or

1000000 + -1
simply input

[cpp] while (scanf("%s%s%s", a, op, b) == 3)
{
printf("%s %s %s\n", a, op, b);
//decide how to output
}[/cpp]

hope it can help

good luck

Posted: Tue Aug 03, 2004 7:13 pm
by minskcity
jackie wrote:After many WAs i change the algorithm. Use double instead of big number.
and i get AC.

hope it can help

good luck
It does help - I've just got AC with a 10-line program. I guess this post is resolved now. :D

problem!!!

Posted: Mon Aug 30, 2004 9:53 am
by shanto86
can any one plz hlp me with this code. i am getting WA.

#include<stdio.h>

void main()
{
long long n1,n2,result;
char expression[1000],op[3];
while(gets(expression))
{
sscanf(expression,"%lld%s%lld",&n1,op,&n2);
printf("%s\n",expression);
if(n1>2147483647)
printf("first number too big\n");
if(n2>2147483647)
printf("second number too big\n");
if(op[0]=='+')
result=n1+n2;
else
result=n1*n2;
if(result>2147483647)
printf("result too big\n");
}
}

Posted: Mon Aug 30, 2004 6:00 pm
by minskcity
Read previos topic - use double instead of long long... If you are given a very big number as an input, it might look like a small number when converted to long long and your code will fail.

Re: problem!!!

Posted: Wed Sep 08, 2004 2:33 pm
by Arm.Turbo
shanto86 wrote:can any one plz hlp me with this code. i am getting WA.

#include<stdio.h>

void main()
{
skip
}
You can't use long long. You have to scan data from input using strings.

Problem 465

Posted: Fri Mar 04, 2005 7:52 am
by hectorUCI
I think this code works but .. i get WA. Could anybody check it, please?

Program ACM465;
var
I,D : LongInt;
p,pm,pp,pei,ped:integer;
S,SI,SD : String;
b:boolean;
Begin
while not eof do
begin
readln( S );
pm:=pos('+',S); pp:=pos('*',S); b:=FALSE;
p:=pm+pp;
if p=0 then continue;
SI:=copy(S,1,p-1);
while not (SI[1] in ['0'..'9']) do delete(SI,1,1);
while not (SI[length(SI)] in ['0'..'9']) do delete(SI,Length(SI),1);
val(SI,I,pei);
SD:=copy(S,p+1,length(S)-p);
while not (SD[1] in ['0'..'9']) do delete(SD,1,1);
while not (SD[length(SD)] in ['0'..'9']) do delete(SD,Length(SD),1);
val(SD,D,ped);
writeln(S);
if (I>32767) or (pei<>0) then
begin
writeln('first number too big');
b:=TRUE;
end;
if (D>32767) or (ped<>0) then
begin
writeln('second number too big');
b:=TRUE;
end;
if (pm<>0) and (I+D>32767) then b := TRUE;
if (pp<>0) and (I*D>32767) then b := TRUE;
if b then
writeln('result too big');
end;
End.

465....Having problem in taking input

Posted: Thu Mar 31, 2005 8:32 pm
by murkho
I am having problem in taking input for problem 465...that is should i use
strtok() or sprintf() ?
if i use sprintf()
then why this line does not work?

sprintf(str,"%s %ch %s",&s1,&ch,& s2);
it can take first number in s1 , the + or * sign in ch
but not second number in s2.

if to use strtok how to use it?

any other possible ways?


please help me . I am waiting for your help.

Posted: Fri Apr 01, 2005 6:42 am
by sumankar
None of strtok()/sprintf() are used for taking input.At least as far as I know.
Maybe you are doing a fgets() and then this strtok() /sprintf stuff ...but I am left to guess.

Code: Select all

sprintf(str,"%s %ch %s",&s1,&ch,& s2); 
Can you tell me the type specifiers for s1, s2 & ch?I am guessing once again,
s1 and s2 are of type char */char [] - in which case your code is wrong.
If s1, s2 are integers - %s has to be changed. So either way this snippet is plain wrong.

Code: Select all

int main()
{
    char a[256], b[256], op[2];
     ...
    while ( 3 == scanf("%s %s %s", a, op, b) )
    {
          /*....a lot of stuff that I wont tell you ;)*/
    }
...
}
is how I get input for this problem.

HTH
Regards,
Suman.

465:Pls.....Help Me

Posted: Wed Jun 01, 2005 9:11 am
by Rocky
Can Any Body Help With Any Tricks Or Special IO Of This Problem
I Get WA All The Time.
Plsss Help Me.

THANK'S IN ADVANCE
Rocky