首页 > 代码库 > UVA 465- Overflow(借助atof函数将字符串改为double型)
UVA 465- Overflow(借助atof函数将字符串改为double型)
Overflow
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluDescription
Overflow
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; }
UVA 465- Overflow(借助atof函数将字符串改为double型)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。