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 给定字符拼成的树,将 ...
随机推荐
- Ubuntu gcc编译报错:format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]
平时用的都是Centos系统,今天偶然在Ubuntu下编译了一次代码,发现报错了: 源码: #include <stdio.h> #include <sys/time.h> # ...
- jquery.validation.js 表单验证
jquery.validation.js 表单验证 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuer ...
- 你知道吗?Web的26项基本概念和技术
这是我在网上看到一篇不错的文章,拿出来与大家分享一下:希望有所帮助 作者: 小鱼 来源: 前端里 发布时间: 2014-08-01 22:56 阅读: 10477 次 推荐: 51 原文链 ...
- java web统计当前访问用户数量
1.使用SessionListener监听器,监听创建与销毁session的操作,利用计数方式记录当前session的数量
- Swift - UIViewController
UIViewController类详解: 通过Nib文件初始化 init(nibName nibName: String?, bundle nibBundle: NSBundle?) println( ...
- Delphi编程建议遵守的规范2---命名规范
1.1.形参命名建议 所有形参的名称都应当表达出它的用途.如果合适的话,形参的名称最好以字母a 为前缀,例如: procedure SomeProc(aUserName:string; aUserAg ...
- Java 8新特性
Java 8版本最大的改进就是Lambda表达式,其目的是使Java更易于为多核处理器编写代码:其次,新加入的Nashorn引擎也使得Java程序可以和JavaScript代码互操作:再者,新的日期时 ...
- 【翻译十四】java-并发之保护块儿
Guarded Blocks Threads often have to coordinate their actions. The most common coordination idiom is ...
- Sexagenary Cycle(天干地支法表示农历年份)
Sexagenary Cycle Time Limit: 2 Seconds Memory Limit: 65536 KB 题目链接:zoj 4669 The Chinese sexagen ...
- [Linux] 解决终端显示乱码问题
[背景] 公司弄了两台新的虚拟机,用来将原先都部署在一台机器上的JIRA, Fisheye, Confluence迁移到这两台机器上,使用SecureCRT进行登录,使用相关命令时,一台出现乱码,另外 ...