465 - Overflow
Moderator: Board moderators
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
[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
and i get AC.
Then i find the judge's input doesn't contain line like
simply input1000000*10000
or
1000000 + -1
[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
problem!!!
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");
}
}
#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");
}
}
Self judging is the best judging!
Re: problem!!!
You can't use long long. You have to scan data from input using strings.shanto86 wrote:can any one plz hlp me with this code. i am getting WA.
#include<stdio.h>
void main()
{
skip
}
Problem 465
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.
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
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.
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.
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.
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.
is how I get input for this problem.
HTH
Regards,
Suman.
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);
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 ;)*/
}
...
}
HTH
Regards,
Suman.
465:Pls.....Help Me
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
I Get WA All The Time.
Plsss Help Me.
THANK'S IN ADVANCE
Rocky