Uva--465 (伪高精度)

2014-06-02 02:02:03

题意&思路:判断是否溢出,用double类型即可。

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 1000;
const int maxint = 2147483647;

int main(){
    char st1[maxn + 5],st2[maxn + 5],tem[5];
    while(cin >> st1 >> tem >> st2){
        cout << st1 << " " << tem << " " << st2 << endl;
        double a,b;
        a = atof(st1);
        b = atof(st2);
        
        if(a > maxint)
            printf("first number too big\n");

        if(b > maxint)
            printf("second number too big\n");

        if(tem[0] == '+' && a + b > maxint)
            printf("result too big\n");

        else if(tem[0] == '*' && a * b > maxint)
            printf("result too big\n");            
    }
    return 0;
}

 

posted @ 2014-06-02 02:03  Naturain  阅读(103)  评论(0编辑  收藏  举报