Ultraviolet A 465 -- overflow (atof function)

Source: Internet
Author: User
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 (TypeIntegerIf you are working Pascal, TypeIntIf 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 values of these three messages as are appropriate :''First number too big'',''Second number too big'',''Result too big''.

Sample Input

300 + 39999999999999999999999 + 11

Sample output

300 + 39999999999999999999999 + 11first number too bigresult too big
 
Originally, it was a simulation question. After wa 7 times, we had no choice but to directly go to the atof function. This function converts the input string to a float (double) type)
 
#include<cstdio>#include <cstdlib>#include <iostream>#include <cstring>using namespace std;const int MAX=2147483647;int main(){char op,a[1100],b[1100];while(cin>>a>>op>>b){cout<<a<<" "<<op<<" "<<b<<endl;double x=atof(a),y=atof(b);if(x>MAX)cout<<"first number too big"<<endl;if(y>MAX)cout<<"second number too big"<<endl;if(op=='+'){double ans=x+y;if(ans>MAX)cout<<"result too big"<<endl;}if(op=='*'){double ans=x*y;if(ans>MAX)cout<<"result too big"<<endl;}}return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.