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)