Uva-465 (overflow)

Source: Internet
Author: User

This question is amazing. Wa has made four rounds... Damn it, C ++ won't be used, and the output should be output as is...

For example:

0000000000000000006*000000000000001

The output is 0000000000000000006*000000000000001.

Instead of 6*1

Import Java. io. *; import Java. util. *; import Java. math. *; public class overflow {public static void main (string [] ARGs) {consumer SC = new consumer (New bufferedinputstream (system. in); bigdecimal bd1, bd2, bd3, ans; string ST1; bd3 = new bigdecimal ("2147483647"); // int 4-2147483648 ~ 2147483647 both 0x7ffffff while (SC. hasnextline () {ST1 = new string (SC. nextline (); system. out. println (ST1); // output as is... String [] STR = st1.split ("[\ + \ *]"); // regular expression, and then write the split () string segmentation method int I = 0 tomorrow, len = st1.length (); Boolean flag = false; while (I <Len) {If (st1.charat (I) = '+ ') {// The flag = true;} I ++;} bd1 = new bigdecimal (STR [0]. trim (); // trim () method, used to clear space bd2 = new bigdecimal (STR [1]. trim (); If (flag = true) {ans = bd1.add (bd2);} else {ans = bd1.multiply (bd2);} If (bd1.compareto (bd3)> 0) {// Compareto () method, used to compare the size between two objects. The return value greater than 0 is equivalent to 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 (); // close the stream. It's just a good habit... }}

 

Uva-465 (overflow)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.