码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-12-10 09:22:47      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   io   ar   color   os   sp   for   

Overflow
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

bubuko.com,布布扣


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

标签:des   style   http   io   ar   color   os   sp   for   

原文地址:http://blog.csdn.net/u013486414/article/details/41833617

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!