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 ...
随机推荐
- 数据库(学习整理)----5--Oracle常用的组函数
其他: 1.oracle中下标是从1开始的,Java下标是从0开始的 函数分类: 日期函数 字符函数 转换函数 数学函数 系统函数 ---在当前月份上面:增加.减少月份 select add_mont ...
- 【JAVA集合】HashMap源码分析(转载)
原文出处:http://www.cnblogs.com/chenpi/p/5280304.html 以下内容基于jdk1.7.0_79源码: 什么是HashMap 基于哈希表的一个Map接口实现,存储 ...
- jQuery 鼠标滑过及选中一行效果
/******* 表格效果 ********/ $("#gird_tbl tbody tr").live('mouseover', function () { $(this).ad ...
- CoffeeScript飞一样的写javascript
之前看到同事在使用coffeescript写js,当我看到那简介的coffee文件,就深深的被coffescript吸引了,简洁的语法,熟练之后会大大提升javascript的开发速度,写脚本也能像飞 ...
- 实现 winform 异步跨线程访问UI控件
在开发winform时经常会用到多线程防止界面出现假死现象,比如当你单击某个按钮时,需要执行很多代码,但是在执行过程中想实时的将当前执行的情况报告给用户,类型进度条或文本什么的. 这个时候很显然,如果 ...
- etTimeout与setInterval方法的区别
etTimeout与setInterval方法的区别 setTimeout()用于设定在指定的时间之后执行对应的函数或代码.,在全局作用域下执行 setTimeout(code,time[,args… ...
- Attributes(1):反射Attribute并输出
using System; using System.Reflection; using System.Text; namespace Attribute01 { class Program { ...
- Python 学习之urllib模块---用于发送网络请求,获取数据(3)
上节内容,是得到了省/直辖市编码,如web='http://m.weather.com.cn/data5/city01',我们需要继续获取此接口的数据,于是进行下面的操作 for i in b ...
- Django设置TIME_ZONE和LANGUAGE_CODE为中国区域
Django默认的timezone是 TIME_ZONE = 'America/Chicago' LANGUAGE_CODE = 'en-us' 设置为中国区域: TIME_ZONE = 'Asia/ ...
- Ubuntu下安装nvidia显卡驱动
layout: post title: Ubuntu下安装nvidia显卡驱动 date: 2015-10-02 17:19:06 categories: 常用命令 tags: 显卡 驱动 最近一直在 ...