标签:des style http io ar color os sp for
Description
Overflow |
Write a program that reads an expression consisting of two non-negative integer and an operator. Determine if either integer or the result of the expression is too large to be represented as a ``normal‘‘ signed integer (type integer if you are working Pascal, type int if you are working in C).
An unspecified number of lines. Each line will contain an integer, one of the two operators + or *, and another integer.
For each line of input, print the input followed by 0-3 lines containing as many of these three messages as are appropriate: ``first number too big‘‘, ``second number too big‘‘, ``result too big‘‘.
300 + 3 9999999999999999999999 + 11
300 + 3 9999999999999999999999 + 11 first number too big result too big
这个是问哪个值超了int类型 int类型的正整数范围为2^31
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define inf 2147483647 char a[1010]; char b[1010]; int main() { char str; double n,m; while(~scanf("%s %c %s",a,&str,b)) { n=atof(a); m=atof(b); printf("%s %c %s\n",a,str,b); if(n>inf) printf("first number too big\n"); if(m>inf) printf("second number too big\n"); if(str=='+'&&n+m>inf) printf("result too big\n"); if(str=='*'&&n*m>inf) printf("result too big\n"); } return 0; }
UVA 465- Overflow(借助atof函数将字符串改为double型)
标签:des style http io ar color os sp for
原文地址:http://blog.csdn.net/u013486414/article/details/41833617