UVA 465 (13.08.02)
| Overflow |
Write a program that reads an expression consisting of twonon-negative integer and an operator. Determine if either integer orthe result of the expression is too large to be represented as a``normal'' signed integer (typeinteger if you are workingPascal, type int if you are working in C).
Input
An unspecified number of lines. Each line will contain an integer, oneof the two operators+ or *, and another integer.
Output
For each line of input, print the input followed by 0-3 linescontaining as many of these three messages as are appropriate: ``firstnumber 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
题意:输入num1 + 或 * num2
若num1大于int可表示的最大值, 那么输出"first number too big"
同理num2的话, 输出"second number too big"
最后还要判定结果是否溢出, 若溢出, 输出"result too big"
都没溢出, 那么就没输出~
AC代码:
#include<stdio.h>
#include<stdlib.h> #define MAX 2147483647 int main() {
char num1[600], num2[600];
char ch;
double n1, n2;
while(scanf("%s %c %s", num1, &ch, num2) != EOF) {
printf("%s %c %s\n", num1, ch, num2);
n1 = atof(num1);
n2 = atof(num2);
if(n1 > MAX)
printf("first number too big\n");
if(n2 > MAX)
printf("second number too big\n");
if(ch == '+' && n1+n2 > MAX)
printf("result too big\n");
if(ch == '*' && n1*n2 > MAX)
printf("result too big\n");
}
return 0;
}
UVA 465 (13.08.02)的更多相关文章
- UVA 10494 (13.08.02)
点此连接到UVA10494 思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~ AC代码: #include<stdio.h> #include<string.h> ...
- UVA 424 (13.08.02)
Integer Inquiry One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...
- UVA 10106 (13.08.02)
Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- UVA 253 (13.08.06)
Cube painting We have a machine for painting cubes. It is supplied withthree different colors: blu ...
- UVA 573 (13.08.06)
The Snail A snail is at the bottom of a 6-foot well and wants to climb to the top.The snail can cl ...
- UVA 10499 (13.08.06)
Problem H The Land of Justice Input: standard input Output: standard output Time Limit: 4 seconds In ...
- UVA 10025 (13.08.06)
The ? 1 ? 2 ? ... ? n = k problem Theproblem Given the following formula, one can set operators '+ ...
- UVA 536 (13.08.17)
Tree Recovery Little Valentine liked playing with binary trees very much. Her favoritegame was con ...
随机推荐
- C# 匿名表达式(Lambda表达式)
匿名表达式 这次来说说Lambda表达式吧,反正也简单,我也不像其他高手那样强调来强调去,只讲一下方法: 准备条件如下: 第一,匿名表达式必须存在与之对应的委托. 只要存在相对应的委托就可以了.接下来 ...
- ACM HDU 1021 Fibonacci Again
#include<iostream> using namespace std; int main() { int n; while(cin>>n) { if((n+1)%4== ...
- VS2008中MFC界面编程Caption中文全是乱码的解决办法 -转载
一.问题 在预览状态下可能看到中文,但是编译运行后对话框中的中文全是问号.即使你用的VS中文版,即使你也用了Unicode编码,即使有条件编译 #ifdef _WIN32LANGUAGE LANG_C ...
- SlidesJS 3.0.4 在手机上遇到的一些问题及解决办法
SlidesJS 3.0.4 http://slidesjs.com 在手机上遇到的一些问题及解决办法 1.手机上打开有sliderjs的页面后, 切换到别的页面再回来时, sliderjs部分不能滑 ...
- CSAPP Lab2: Binary Bomb
著名的CSAPP实验:二进制炸弹 就是通过gdb和反汇编猜测程序意图,共有6关和一个隐藏关卡 只有输入正确的字符串才能过关,否则会程序会bomb终止运行 隐藏关卡需要输入特定字符串方会开启 实验材料下 ...
- js快速排序法
var quickSort = function(arr) { if (arr.length <= 1) { return arr; } var pivotIndex = Math.floor( ...
- phpcms安装完成后总是跳转到install/install.php
很多人在本地安装phpcms后总是跳转到install/install.php.由于很多人是第一次使用phpcms,不知道为何会出现这个错误.出现这个大都是phpcms的缓存所致. 如何解决ph ...
- 帝国cms7.0修改“信息提示”框
具体修改查看e/message/index.php文件 上传一张合适用的图 <table width="600" height="224" border= ...
- 【关于php】Appserv的安装注意事项
之前的安装,问题应该不大,一路点“安装——Next——next·····”就行,下面是一些注意事项: (1)AppServ安装路径的选择.具体安装在哪个磁盘下用户可以自行选择,也可以使用默认的安装位置 ...
- java简单字符串处理
在实际的开发工作中,对字符串的处理是最常见的编程任务. 本题目即是要求程序对用户输入的串进行处理.具体规则如下: 1. 把每个单词的首字母变为大写. 2. 把数字与字母之间用下划线字符(_)分开,使得 ...