您的位置:首页 > 其它

UVA 465- Overflow(借助atof函数将字符串改为double型)

2014-12-09 23:52 441 查看
Overflow
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
Submit Status

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

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


这个是问哪个值超了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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: