Simplified Version Big Data Addition

Source: Internet
Author: User

# Include <iostream>
# Include <cstring>
# Define l 1000000000
Class bignum {
PRIVATE:
Int num [101], Len;
Public:
Bignum () {num [0] = 0; Len = 0 ;}
Friend bignum operator + (bignum A, bignum B ){
Int I, L1 = A. Len, L2 = B. Len;
Bignum temp;
For (I = 0; I <L1 | I <L2; I ++ ){
If (I> = L1) temp. Num [I] + = B. Num [I];
Else if (I> = l2) temp. Num [I] + = A. Num [I];
Else temp. Num [I] + = A. Num [I] + B. Num [I];
If (temp. Num [I]> = L ){
Temp. Num [I + 1] = 1;
Temp. Num [I] % = L;
} Else temp. Num [I + 1] = 0;
}
Temp. Len = I + temp. Num [I];
Return temp;
}
Void operator = (int x ){
Num [0] = X;
Len = 1;
}
Bool operator = (int x ){
If (LEN> 1) return 0;
Return num [0] = X;
}
Int CMP (bignum ){
If (A. Len! = Len ){
If (LEN> A. Len) return 1;
Return-1;
}
Int I, S = Len;
For (I = s-1; I> = 0; I --){
If (Num [I]> A. Num [I]) return 1;
If (Num [I] <A. Num [I]) Return-1;
}
Return 0;
}
Void print (){
Int I;
Printf ("% d", num [Len-1]);
For (I = Len-2; I> = 0; I --){
Printf ("% 09d", num [I]);
}
Printf ("/N ");
}
Void get (){
Char STR [101];
Int o = 0, S, ten = 1;
Len = 0;
Scanf ("% s", STR );
S = strlen (STR );
While (s --){
O + = (STR [s]-48) * ten;
Ten * = 10;
If (ten = 1e9 | S = 0 ){
Num [Len] = O;
Len ++;
O = 0; Ten = 1;
}
}
}
};

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.