Poj 1001 Java big data class

Source: Internet
Author: User

Today, in the invitation to the local big competition, question a is a big number question, Java is not used for large numbers, and C ++ is not proficient in writing large numbers templates, so I am too lazy to write the results. As a result, I had to win the third prize...

Today:

Import Java. math. bigdecimal; import Java. util. imports; import Java. math. biginteger; public class math {/*** @ Param ARGs */Private Static final int default_div_scale = 10; public static void main (string [] ARGs) {// todo auto-generated method stub/* While (true) {partition input = new partition (system. in); int num = input. nextint (); system. out. println (Num);} * // biginteger x = new biginteger (44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444111 "); // biginteger y = new biginteger ("-555555555555555555555555555555555555555555 "); int M = 1233; biginteger x = new biginteger ("12422333332222222222223443211"); biginteger y = new biginteger ("12"); biginteger K = new biginteger ("e", 16); system. out. println (k); system. out. println (X. add (y); system. out. println (Y. ABS (); system. out. println (Y. compareto (x); biginteger n = x. divide (Y. ABS (); system. out. println (n); system. out. println (N. multiply (Y. ABS (); system. out. println (Y. gcd (x); system. out. println (X. gcd (y); system. out. println (X. subtract (y); system. out. println (X. pow (m);/* system. out. print ("input data: \ n"); system. out. println ("input data:"); partition input = new partition (system. in); float num = input. nextfloat (); system. out. println (Num); */system. out. println ("returns the remainder of a Large Number:"); system. out. println (X. moD (y); bigdecimal A = new bigdecimal ("11111111.213211"); system. out. println ("A =" + a);/* biginteger B = new biginteger ("11111111.213211"); */biginteger B = new biginteger ("11111111"); system. out. println ("B =" + B); bigdecimal c = new bigdecimal ("12222.121"); system. out. println ("c =" + C); system. out. println ("A + C =" +. add (c ));}}

Question link: http://poj.org/problem? Id = 1001

I wrote the Java code for the first time and handed it over once. Sang Xin... Codeforces is ready.

Poj100 questions, with pictures to commemorate ,,,,,,,,,,,,


Remember, all Java class names submitted by poj must be changed to main.

Import java. Math. biginteger; import java. Math. bigdecimal; import java. util. Imports; import java. Io. *; // do you know which packages are imported? Public class exponentiation {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub1_input = new partition (system. in);/* read: * reads data from the console using the objects defined by the category class. The category class is in Java. util. * package * contains input = new partition (system. in); * int n = input. nextint (); * biginteger nn = input. nextbiginteger (); *...................................... */while (input. hasnext () // equals! = EOF {int N; bigdecimal A = input. nextbigdecimal (); // read a bigdecima1= input. nextint (); A =. pow (n); // returns the bigdecimal whose value is (thisn). This power is accurately calculated to provide infinite precision. // POW (int n, mathcontext MC) returns the bigdecimal whose value is (thisn. A =. striptrailingzeros ();/* Public bigdecimal striptrailingzeros (strip stripping, trailing, however, it indicates that the bigdecimal * 1.22222300000 with all tail Zeros is of the 1.222223 or bigdeciaml type after they are used */string STR =. toplainstring ();/** note the difference between toplainstring () and tostring () * For: bigdecimal s; S = (0.4321 ^ 20) * string STR = S. toplainstring (); * system. out. println (STR); * output: 0.0000000514855464107 ..... 01 ** if string STR = S. tostring (); * The output is: 5.14855464107 .... 01e-8 */If (Str. startswith ("0. ") // start with {STR = Str. substring (1);/* substring is a method for intercepting strings in Java * two parameter passing Methods * One is public string substring (INT deginindex) * returns a new string, which is a substring of this string. The string starts from the character at the specified index until the end of the string * the other is public string substring (INT deginindex, int endindex) * returns a new string, which is also a substring. The character from beginindex * until the index to the endindex-1. Therefore, the length of the string is endindex-beginindex *** substr **. This method is used to return a substring * substr (START, length) of the specified length starting from the specified position ); */} system. out. println (STR );}}}

Java submission is really slow, more than 100 ms

Good resources: http://man.ddvip.com/program/java_api_zh/java/math/BigDecimal.html#stripTrailingZeros ()

Http://www.chineselinuxuniversity.net/articles/50293.shtml

Http://wenku.baidu.com/view/9463cec7aa00b52acfc7caa8.html

Stick to it

Related Article

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.