(Maintenance) high-precision template (Division missing), high-precision Division
# Include <cstdio> # include <cstring> # include <algorithm> typedef long B _INT; const char p_c [] = "% 08lld "; const char I _c [] = "% lld"; static MEMBERS OF THE struct Bigint {/* basic type (char, int, float, double, etc.) can be declared and initialized in the class, non-basic classes (char [], string, custom, etc.) must be declared in the class and initialized outside the class. */Static const B _INT p = 8; // press the p bit. The four-digit addition method of the int pressure may overflow the static const B _INT base = 100000000; // press the p bit, maximum number of 10 ^ p-1static const int maxl = 3000; B _INT a [maxl]; // a [0]-> len, a [I]-> Number of I p bits Bigint () {memset (a, 0, sizeof (a);} // Bigint (char * str) // {// memset (a, 0, sizeof (a); // B _INT k = 0, p = 1; // char * str1 = str + strlen (str) -1; // while (str1> = str) // {// k = k + p * (* str1-48); // if (p = base) // {// a [++ a [0] = k % base; // k/= base; // p = 1; //} // str1 --; // p * = 10; //} // A [++ a [0] = k; //} Bigint (const Bigint & B) {memcpy (a, B. a, sizeof (a);} Bigint & operator = (const Bigint & B) {memcpy (a, B. a, sizeof (a);} Bigint & operator = (char * str) {memset (a, 0, sizeof (a); B _INT k = 0, p = 1; char * str1 = str + strlen (str)-1; while (str1> = str) {k = k + p * (* str1-48); if (p = base) {a [++ a [0] = k % base; k/= base; p = 1;} str1 --; p * = 10 ;} a [++ a [0] = k; return * this;} Bigint operator + (const Bigint & B) const {Bigint c; B _INT I; c. a [0] = std: max (a [0], B. a [0]); for (I = 1; I <= c. a [0]; I ++) {c. a [I] + = a [I] + B. a [I]; c. a [I + 1] = c. a [I]/base; c. a [I] % = base;} if (c. a [c. a [0] + 1]> 0) c. a [0] ++; return c;} Bigint operator * (const Bigint & B) const {Bigint c; B _INT I, j; for (I = 1; I <= a [0]; I ++) for (j = 1; j <= B. a [0]; j ++) c. a [I + J-1] + = a [I] * B. a [j]; c. a [0] = a [0] + B. a [0]-1; for (I = 1; I <= c. a [0]; I ++) {c. a [I + 1] + = c. a [I]/base; c. a [I] % = base;} if (c. a [c. a [0] + 1]> 0) c. a [0] ++; return c;} Bigint operator- (Const Bigint & B) const // requires that the subtrahend be smaller than the subtrahend {Bigint c; B _INT I; c. a [0] = std: max (a [0], B. a [0]); for (I = 1; I <= c. a [0]; I ++) c. a [I] = a [I]-B. a [I]; for (I = 1; I <= c. a [0]; I ++) if (c. a [I] <0) {c. a [I] + = base; c. a [I + 1] --;} while (c. a [c. a [0] = 0 & c. a [0]> 0) c. a [0] --; return c;} Bigint & operator + = (const Bigint & B) {* this = * this + B; return * this ;} bigint & operator-= (const Bigint & B) {* this = * this-B; return * this;} Bigint & operator * = (const Bigint & B ){* This = (* this) * B; return * this;} bool operator <(const Bigint & B) const {if (a [0]! = B. a [0]) return a [0] <B. a [0]; for (B _INT I = a [0]; I> 0; I --) if (a [I]! = B. a [I]) return a [I] <B. a [I]; return false; // equal}/* const is added after a non-static member function (a compilation error occurs after a non-member function or a static member function is added ), this pointer implicitly passed in by the member function is the const pointer, which determines that in this member function, any modification to the member operations of the class where it is located is not allowed (because the const reference to this pointer is implicit); the only exception is the mutable modified member. Member functions with const added can be called by non-const objects and const objects, but member functions without const can only be called by non-const objects. The lower part of B is const, And the const function cannot modify its data member */bool operator> (const Bigint & B) const {return B <* this;/* if (a [0]! = B. a [0]) return a [0]> B. a [0]; for (int I = a [0]; I> 0; I --) if (a [I]! = B. a [I]) return a [I]> B. a [I]; return false; // equal */} bool operator <= (const Bigint & B) const {return! (B <* this);/* if (a [0]! = B. a [0]) return a [0]> B. a [0]; for (int I = a [0]; I> 0; I --) if (a [I]! = B. a [I]) return a [I]> B. a [I]; return true; // equal */} bool operator >=( const Bigint & B) const {return! (* This <B);/* if (a [0]! = B. a [0]) return a [0]> B. a [0]; for (int I = a [0]; I> 0; I --) if (a [I]! = B. a [I]) return a [I]> B. a [I]; return true; // equal */} bool operator = (const Bigint & B) const {if (a [0]! = B. a [0]) return false; for (B _INT I = a [0]; I> 0; I --) if (a [I]! = B. a [I]) return false; return true;} bool operator! = (Const Bigint & B) const {return! (* This = B);} void print () {printf (I _c, a [a [0]); for (B _INT I = a [0]-1; i> 0; I --) printf (p_c, a [I]) ;}} x [3]; char str [10010]; int main () {scanf ("% s", str); x [0] = str; scanf ("% s", str); x [1] = str; // if (x [0] <x [1]) // {// printf ("-"); // x [2] = x [0]; // x [0] = x [1]; // x [1] = x [2]; ///} // (x [0]-x [1]). print (); // (x [0] * x [1]). print (); // printf ("% d", x [0]> x [1]); (x [1] = x [1]). print (); // puts (""); // x [0]. print (); // puts (""); // x [1]. print (); return 0 ;}