HDOJ-ACM1002 (Java implementation Custom large number processing class Mbiginteger)

Source: Internet
Author: User

Reprint declaration: The original text transferred from http://www.cnblogs.com/xiezie/p/5502809.html

Java language implementations:

ImportJava.util.*;ImportJava.io.*; Public classmain{ Public Static voidMain (string[] arg) {main M=NewMain (); Scanner Scan=NewScanner (NewBufferedinputstream (system.in)); intn =Scan.nextint (); intL =N;  while(N--! =0) {Mbiginteger integer= M.NewMbiginteger (Scan.next ()); Mbiginteger Integer2= M.NewMbiginteger (Scan.next ()); System.out.println ("Case" + (L-n) + ":"); System.out.println (integer+ "+" + integer2 + "=" +Integer.add (integer2)); if(n!=0) {System.out.println ();    }} scan.close (); }        classmbiginteger{PrivateMbiginteger () {}; PrivateString S;  PublicMbiginteger (String s) { This. Sets (s); }                 PublicMbiginteger Add (Mbiginteger integer) {//handle only positive integers            Char[] Ch1 =GetS (). ToCharArray (); Char[] CH2 =integer.gets (). ToCharArray (); intLen =ch1.length; intLen2 =ch2.length; intn =Len; Char[] resultchars; if(len<len2) {N=Len2; } resultchars=New Char[n]; BooleanOverten =false; intans;  while(len!=0&&len2!= 0){                into = 0; if(overten) {o++; } ans= Getintvalueat (CH1, len-1) + getintvalueat (CH2, len2-1) +o; if(Ans > 9) {Overten=true; }Else{Overten=false; } resultchars[--n] = (Char) (ans%10 + ' 0 '); Len-- ; Len2-- ; }             while(Len--! =0){                into = 0; if(overten) {o++; } ans= Getintvalueat (CH1, Len) +o; if(Ans > 9) {Overten=true; }Else{Overten=false; } resultchars[--n] = (Char) (ans%10 + ' 0 '); }             while(Len2--! =0){                into = 0 ; if(overten) {o++; } ans= Getintvalueat (CH2, len2) +o; if(Ans > 9) {Overten=true; }Else{Overten=false; } resultchars[--n] = (Char) (ans%10 + ' 0 '); }            if(Overten) {Sets ("1". Concat (string.valueof (Resultchars))); }Else{Sets (string.valueof (Resultchars)); }            return  This; } @Override PublicString toString () {return  This. GetS (); }         PublicString GetS () {returns; }         Public voidsets (String s) { This. S =s; }                 Public intGetintvalueat (Char[] C,inti) {            returnc[i]-' 0 '; }    }}

HDOJ-ACM1002 (Java implementation Custom large number processing class Mbiginteger)

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.