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 ...
随机推荐
- max取得数组的最大值
var arr = [1,2,3,4,5,2,2,4,52,5,6,5,4,4]; var maxNum = Math.max.apply(Math,arr); var maxIndex = arr. ...
- 菜鸟日记之JSP二 内置对象的理解
·最近学习JSP了,对编程和网络又有了一些理解.无论是现实中人与人的交流,还是网络世界的接触,都是在相互表达自己的意思让别人知道,并理解对方的信息.然后我们知道的事情不断的变多,会又交杂出新的内容,不 ...
- Linux的cat、more、less的区别
cat命令功能用于显示整个文件的内容单独使用没有翻页功能因此经常和more命令搭配使用,cat命令还有就是将数个文件合并成一个文件的功能. more命令功能:让画面在显示满一页时暂停,此时可按空格健继 ...
- [Neural Networks] Dropout阅读笔记
多伦多大学Hinton组 http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf 一.目的 降低overfitting的风险 二.原理 ...
- 使用jQuery播放/暂停 HTML5视频
文章来自:http://blog.okbase.net/jquery2000/archive/4485.html 我尝试用jQuery控制HTML5视频,两个视频分别在两个tab中,我希望点中tab后 ...
- CANoe 入门 Step by step系列(二)CAPL编程【转】
CAPL就是Communication Application Programming Laguage的缩写,CAPL类似于C语言的语法,因此所有的语法请参考C语言教程,这里不在这里进行详述,关于C语 ...
- Python: 设计模式 之 工厂模式例(1)
#!/usr/bin/env python #coding=utf-8 # # 工厂模式一例 # 版权所有 2014 yao_yu (http://blog.csdn.net/yao_yu_126) ...
- 学习Swift -- 泛型
泛型 泛型代码可以让你写出根据自我需求定义.适用于任何类型的,灵活且可重用的函数和类型.它的可以让你避免重复的代码,用一种清晰和抽象的方式来表达代码的意图. 泛型所解决的问题 先来看一个交换两个int ...
- OpenCV for c++Builder
整理日: 20154/6 Borland C++BuilderでOpenCVを使う 確認 Turbo C++ 2007/03 1. ダウンロード&インストール http://sourcefor ...
- Android程序的隐藏与退出
转自Android程序的隐藏与退出 Android的程序无需刻意的去退出,当你一按下手机的back键的时候,系统会默认调用程序栈中最上层Activity的Destroy()方法来销毁当前Activit ...