465-overflow
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=97&page=show_problem &problem=406
Write a program so reads an expression consisting of two non-negative integer and a operator. Determine if either integer or the result of the expression was too large to be represented as a ' normal ' signed integer (Type integer If you are are working Pascal, type int If you are working in C).
Input
An unspecified number of lines. Each line would contain an integer, one of the two operators + or *, and another integer.
Output
For each line of input, print the "input followed by 0-3 lines containing as many to these three messages as are Appropriat E: ' Number too big ', ' second number too ', ' result too big '.
Sample Input
300 + 3
9999999999999999999999 + 11
Sample Output
300 + 3
9999999999999999999999 + 11
Number Too big
Result too big
As described in the title.
Complete code:
/*0.019s*/
#include <cstdio>
const double maxint = -1u >> 1;
Char str[600];
int main ()
{
double A, b;
char op;
while (gets (str))
{
puts (str);
SSCANF (str, "%lf%c%lf", &a, &op, &b);
if (a > Maxint) puts ("number too big");
if (b > Maxint) puts ("second number too big");
if (op = = ' + ' && A + B > Maxint | | | op = = ' * ' && A * b > Maxint) puts ("result too big");
} return
0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/