uva465 - Overflow
2016-07-13 16:27
337 查看
uva465 - Overflow
题目大意:检查两个数相加相乘会不会溢出解题思路:atof直接把字符串读成浮点数,然后浮点数的范围比int的大的多,直接比较就行了。
#include<cstdio> #include<cstdlib> #include<cstring> char str1[10000]; char str2[10000]; char op; int limit=2147483647; int main(){ double a,b; while((scanf("%s %c %s",str1,&op,str2))!=EOF) { a=atof(str1); b=atof(str2); printf("%s %c %s\n",str1,op,str2); if(a>limit)printf("first number too big\n"); if(b>limit)printf("second number too big\n"); if(op=='+') if(a+b>limit)printf("result too big\n"); if(op=='*') if(a*b>limit)printf("result too big\n"); memset(str2,0,sizeof(str2)); memset(str1,0,sizeof(str1)); } return 0; }
相关文章推荐
- Quartz2D绘制字体和图形
- Qt学习之路(60): 创建shared library
- HDU 4288 Coder(线段树+离线处理)
- 前端面试经典题目合集--77题
- 自定义圆头柱状图
- c# 拆分合并字符串 Split Join
- LeetCode 17. Letter Combinations of a Phone Number高效解法
- ioctl用法详解
- Qt学习之路(59): 编写跨平台的程序
- 实现TOOLBAR中颜色对话框的添加
- (第13讲)哈希表的开放地址法中的线性探测
- Same-origin security policy
- 【iOS】网络操作与AFNetworking
- nginx如何设置自定义404页面
- UVa 10106 Product
- 自我介绍和决心书
- C# 委托、事件
- oracle日期函数2!
- 将博客搬至CSDN
- the service threw an unknown exception in SCOM 2012