您的位置:首页 > 其它

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).

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 UVA - 465 Overflow