这道题很奇葩啊,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)的更多相关文章

  1. uva 465 - Overflow 高精度还是浮点数?

    uva 465 - Overflow  Overflow  Write a program that reads an expression consisting of two non-negativ ...

  2. UVa 465 Overflow——WA

    上次那个大数开方的高精度的题,UVa113 Power of Cryptography,直接两个double变量,然后pow(x, 1 / n)就A过去了. 怎么感觉UVa上高精度的题测试数据不给力啊 ...

  3. UVA 465 (13.08.02)

     Overflow  Write a program that reads an expression consisting of twonon-negative integer and an ope ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. Volume 1. Big Number(uva)

    如用到bign类参见大整数加减乘除模板 424 - Integer Inquiry #include <iostream> #include <string> #include ...

  6. 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 2(Big Number)

    这里的高精度都是要去掉前导0的, 第一题:424 - Integer Inquiry UVA:http://uva.onlinejudge.org/index.php?option=com_onlin ...

  7. 【转载】C# 中的委托和事件(详解)

    <div class="postbody"> <div id="cnblogs_post_body" class="blogpost ...

  8. 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 ...

  9. 【UVa】Palindromic Subsequence(dp+字典序)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=465&page=s ...

  10. UVa 10562 Undraw the Trees 看图写树

    转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...

随机推荐

  1. poj2492(种类并查集/各种解法)

    题目链接: http://poj.org/problem?id=2492 题意: 有t组测试数据, 对于每组数据,第一行n, m分别表示昆虫的数目和接下来m行x, y, x, y表示教授判断x, y为 ...

  2. php 删除文件夹

    <?php // ./tp // ./tp/Public function deldir($dirname) { if(!file_exists($dirname)) { die("文 ...

  3. 最稳定 性能最好 的 Linux 版本?

    Ubuntu太他妈不稳定了,简直是一坨屎 CentOS.Ubuntu.Debian三个linux比较异同http://blog.csdn.net/educast/article/details/383 ...

  4. Web框架之Tornado

    概述 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了 ...

  5. Solr入门之(8)中文分词器配置

    Solr中虽然提供了一个中文分词器,但是效果很差,可以使用IKAnalyzer或Mmseg4j 或其他中文分词器. 一.IKAnalyzer分词器配置: 1.下载IKAnalyzer(IKAnalyz ...

  6. jQuery easyUI datagrid 增加求和统计行 分类: JavaScript 2015-01-14 17:46 2178人阅读 评论(0) 收藏

    在datagrid的onLoadSuccess事件增加代码处理. <style type="text/css"> .subtotal { font-weight: bo ...

  7. cordova+angularJS+ionic

    1.创建项目 2.路由 angular.module("starter",['ionic']) // 依赖 ionic 提供的ui-router .config(function ...

  8. WPF MVVM模式下实现ListView下拉显示更多内容

    在手机App中,如果有一个展示信息的列表,通常会展示很少一部分,当用户滑动到列表底部时,再加载更多内容.这样有两个好处,提高程序性能,减少网络流量.这篇博客中,将介绍如何在WPF ListView中实 ...

  9. [Linux][Hadoop] 运行WordCount例子

    紧接上篇,完成Hadoop的安装并跑起来之后,是该运行相关例子的时候了,而最简单最直接的例子就是HelloWorld式的WordCount例子.   参照博客进行运行:http://xiejiangl ...

  10. Microshaoft WinDbg cmdtree

    windbg ANSI Command Tree 1.0 title {"Microshaoft Commands"} body {"cmdtree"} {&q ...