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

UVA_ Overflow

时间:2014-10-25 15:47:50      阅读:182      评论:0      收藏:0      [点我收藏+]

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

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

 

 

这道题考的是 atof 的用法;
atof 把字符串转换成浮点数;
 
代码:
bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #define UNIT 10
 6 #define MAX 2147483647
 7 
 8 using namespace std;
 9 
10 char a[1000],b[1000],ch;
11 int main()
12 {
13     //freopen("ACM.txt","r",stdin);
14     while(scanf("%s %c %s", a, &ch, b)!=EOF)
15     {
16         printf("%s %c %s\n",a,ch,b);
17         double x1,x2;
18         x1=atof(a);
19         x2=atof(b);
20         if(x1>MAX)
21         cout<<"first number too big"<<endl;
22         if(x2>MAX)
23         cout<<"second number too big"<<endl;
24         if(ch==+&&x1+x2>MAX||ch==*&&x1*x2>MAX)
25         cout<<"result too big"<<endl;
26 
27     }
28     return 0;
29 }
View Code

 

 

UVA_ Overflow

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

原文地址:http://www.cnblogs.com/M-D-LUFFI/p/4050194.html

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