题目链接:Overflow UVA - 465
题目没有卡精度,可以使用double类型水过。
float:3.40282e+038 ~ 1.17549e-038
double:1.79769e+308 ~ 2.22507e-308
long double:1.18973e+4932 ~ 3.3621e-4932
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <climits>
using namespace std;
const int N=512;
char s1[N],s2[N];
int main()
{
char c;
while(~scanf("%s %c %s",s1,&c,s2))
{
double a=atof(s1);
double b=atof(s2);
printf("%s %c %s\n",s1,c,s2);
if(a>INT_MAX)
printf("first number too big\n");
if(b>INT_MAX)
printf("second number too big\n");
if(c=='+'&&a+b>INT_MAX)
printf("result too big\n");
if(c=='*'&&a*b>INT_MAX)
printf("result too big\n");
}
return 0;
}