UVA - 465 Overflow
2014-08-20 15:54
323 查看
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).
+ or *, and another integer.
integer if you are working Pascal, type int if you are working in C).
Input
An unspecified number of lines. Each line will 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 of these three messages as are appropriate: ``first number too big'', ``second number too big'', ``result too big''.Sample Input
300 + 3 9999999999999999999999 + 11
Sample Output
300 + 3 9999999999999999999999 + 11
first number too big
result too big
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #define N 1000 const int MAX = 2147483647; //const int MAX = (2 << 31) - 1; using namespace std; int main() { char a , b ; char ch; while(scanf("%s %c %s",a,&ch,b) != EOF) { printf("%s %c %s\n",a,ch,b); if(atof(a) > MAX) printf("first number too big\n"); if (atof(b) > MAX) printf("second number too big\n"); if (ch == '+') { if(atof(a) + atof(b) > MAX) printf("result too big\n"); } if (ch == '*') { if (atof(a) * atof(b) > MAX) { printf("result too big\n"); } } memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); } return 0; }
相关文章推荐
- [UVa] 465 - Overflow
- UVa 465 - Overflow
- UVA 465 Overflow
- UVa 465 Overflow
- UVA - 465 Overflow
- uva 465 overflow
- UVA - 465 Overflow
- UVa 465 Overflow
- UVa - 465 - Overflow
- UVa 465 Overflow——WA
- UVA-465 Overflow
- UVA - 465 - Overflow
- UVA 465-Overflow
- 高精度 UVA465 Overflow
- UVa:465 - Overflow
- uva 465 Overflow
- UVA 465- Overflow(借助atof函数将字符串改为double型)
- uva 465 Overflow(借助double型进行比较)
- UVA 465 - Overflow
- uva-465-Overflow