uva-465(overflow)
这道题很奇葩啊,WA了4发。。。妈的,用c++也不至于,输出竟然要原样输出。。。
例如:
0000000000000000006 * 000000000000001
输出是 0000000000000000006 * 000000000000001
而不是 6 * 1
import java.io.*;
import java.util.*;
import java.math.*; public class Overflow {
public static void main(String[] args){
Scanner sc = new Scanner(new BufferedInputStream(System.in));
BigDecimal bd1, bd2, bd3, ans;
String st1;
bd3 = new BigDecimal("2147483647"); ///int 4位 -2147483648 ~ 2147483647 既 0x7ffffff
while(sc.hasNextLine()){
st1 = new String(sc.nextLine());
System.out.println(st1); ///原样输出。。。
String[] str= st1.split("[\\+\\*]"); ///正则表达式,明天再写 split() 字符串分割方法 int i = 0, len = st1.length();
boolean flag = false;
while(i < len){
if((st1.charAt(i)) == '+'){ //String类中用于获取每一个字符的方法
flag = true;
}
i++;
}
bd1 = new BigDecimal(str[0].trim()); ///trim()方法,用于清空空格
bd2 = new BigDecimal(str[1].trim());
if(flag == true){
ans = bd1.add(bd2);
}else{
ans = bd1.multiply(bd2);
} if(bd1.compareTo(bd3) > 0){ ///compareTo()方法,用于比较两个对象间的大小, 返回 大于0 相当于 bd1 > bd3
System.out.println("first number too big");
}
if(bd2.compareTo(bd3) > 0){
System.out.println("second number too big");
}
if(ans.compareTo(bd3) > 0){
System.out.println("result too big");
}
}
sc.close(); ///关闭流,只是养成好习惯吧。。。
}
}
uva-465(overflow)的更多相关文章
- uva 465 - Overflow 高精度还是浮点数?
uva 465 - Overflow Overflow Write a program that reads an expression consisting of two non-negativ ...
- UVa 465 Overflow——WA
上次那个大数开方的高精度的题,UVa113 Power of Cryptography,直接两个double变量,然后pow(x, 1 / n)就A过去了. 怎么感觉UVa上高精度的题测试数据不给力啊 ...
- UVA 465 (13.08.02)
Overflow Write a program that reads an expression consisting of twonon-negative integer and an ope ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Volume 1. Big Number(uva)
如用到bign类参见大整数加减乘除模板 424 - Integer Inquiry #include <iostream> #include <string> #include ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 2(Big Number)
这里的高精度都是要去掉前导0的, 第一题:424 - Integer Inquiry UVA:http://uva.onlinejudge.org/index.php?option=com_onlin ...
- 【转载】C# 中的委托和事件(详解)
<div class="postbody"> <div id="cnblogs_post_body" class="blogpost ...
- UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494
白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...
- 【UVa】Palindromic Subsequence(dp+字典序)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=465&page=s ...
- UVa 10562 Undraw the Trees 看图写树
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...
随机推荐
- Vector_h
#ifndef VECTOR_H #define VECTOR_H #include <algorithm> template<typename Object> class V ...
- 创建DLL、Lib以及使用DLL、Lib
1.要在生成DLL文件的同时生成Lib文件,函数声明时前面要加__declspec(dllexport). 可在头文件中如下定义: #ifndef __MYDLL_H#define __MYDLL_H ...
- Django环境配置
Django安装 #安装最新版本的Django $ pip install django #或者指定安装版本 pip install -v django==1.7.1 项目创建 $ django-ad ...
- 理解KMP算法
母串:S[i] 模式串:T[i] 标记数组:Next[i](Next[i]表示T[0~i]最长前缀/后缀数) 先来讲一下最长前缀/后缀的概念 例如有字符串T[6]=abcabd接下来讨论的全部是真前缀 ...
- 三、jQuery--Ajax基础--Ajax全接触--jQuery中的AJAX
用jQuery实现Ajax jQuery.ajax([settings]) type:类型,“POST”或“GET”,默认为“GET” url:发送请求的地址 data:是一个对象,连同请求发送到服务 ...
- NBU官方Doc網址https://www.veritas.com/support/en_US/article.DOC5332
NBU(NetBackup) 7.0之後的版本官方文檔鏈接地址: https://www.veritas.com/support/en_US/article.DOC5332
- <转>WCF实例化模式与高并发处理
WCF实例化模式与高并发控制 1.实例化模式InstanceModel 1.1 PerCall:单调模式 每次调用都会产生一个实例 例[ServiceBehavior(InstanceContextM ...
- php调用phpqrcode.php生成二维码
下载phpqrcode.php 下载地址: http://files.cnblogs.com/files/qhorse/phpqrcode.rar qrcode.php文件: <?php inc ...
- hdu 4277 2012长春赛区网络赛 dfs+hashmap ***
hashmap判重大法好 #include<cstdio> #include<iostream> #include<algorithm> #include<c ...
- 把浏览器的私有模式添加到VS中
题记:在用VS进行Web开发的时候,常常希望VS的调试不会对浏览器造成固定的影响,那么使用浏览器的私有模式来启动就很有必要. 前几天SCOTT HANSELMAN分享了一个开发Web应用程序的小技巧, ...