019: Don't call it. This big integer is simplified !, 019 integer simplification
Total time limit: 1000 ms memory limit: Fill in the blanks in the 65536kB description program and output the specified result # include <iostream> # include <cstring> # include <cstdlib> # include <cstdio> using namespace std; const int MAX = 110; class CHugeInt {// Add your code here}; int main () {char s [210]; int n; while (cin> s> n) {CHugeInt a (s); CHugeInt B (n); cout <a + B <endl; cout <n + a <endl; cout <a + n <endl; B + = n; cout <++ B <endl; cout <B ++ <endl; cout < B <endl;} return 0;} Input Multiple groups of data, each of which is two non-negative integers s and n. S can be up to 200 BITs. n can be expressed as an int to output 6 rows of data to each group. The content is as follows: sample input 99999999999999999999999999888888888888888812345678901234567789 6 sample output 126
In this case, you need to write three constructors: No parameter, int parameter, and char * parameter. Three + operators need to be reloaded, which correspond to CHugeInt + int, int + CHugeInt, CHugeInt + CHugeInt, and the front ++ and back ++ must be reloaded, A <overload is also required. The Code is as follows:
# Include <iostream> # include <cstring> # include <cstdlib> # include <cstdio> using namespace std; const int MAX = 110; class CHugeInt {// Add your code here: private: char maxNum [210]; int len; public: CHugeInt (char * s) {strcpy (maxNum, s ); int I = 0, j = strlen (s)-1; while (I <j) {swap (maxNum [I], maxNum [j]); I ++; j --;} // cout <"init:" <maxNum <endl; len = strlen (s ); // cout <"Init success" <endl;} CHugeInt () {len = 0;} CHugeInt (int n) {int I = 0; if (n = 0) {maxNum [I ++] = '0';} else {while (n) {maxNum [I ++] = n % 10 + '0'; n = n/10;} maxNum [I] = '\ 0'; len = I; // cout <maxNum <endl;} CHugeInt operator + (CHugeInt & a) {// cout <"hrer" <endl; int I = 0, j = 0; int t, sum = 0; CHugeInt temps; strcpy (temps. maxNum, maxNum); temps. len = len; // cout <"before:" <temps. maxNum <endl; // maxNum = new char [strlen (. maxNum) + 1]; // cout <. len <"," <len <endl; int flag = 0; while (j <. len & I <temps. len) {t =. maxNum [j]-'0'; int te = temps. maxNum [I]-'0'; sum = t + te; // cout <t <"+" <te <": "<sum <endl; if (sum> = 10) {temps. maxNum [I] = sum % 10 + '0'; // cout <temps. maxNum [I] <endl; temps. maxNum [I + 1] = sum/10 + temps. maxNum [I + 1]; if (I + 1> = temps. len) {temps. maxNum [I + 1] + = '0';} flag = 1;} else {// cout <"sum:" <sum <endl; flag = 0; temps. maxNum [I] = sum + '0';} // cout <temps. maxNum [I] <endl; I ++, j ++; sum = 0 ;}while (j <. len) {if (flag = 1) {temps. maxNum [I + 1] =. maxNum [j]; I ++, j ++;} else {temps. maxNum [I] =. maxNum [j]; I ++, j ++ ;}} if (I >= len) {if (flag = 1) {temps. maxNum [I + 1] = '\ 0'; temps. len = I + 1;} else {temps. maxNum [I] = '\ 0'; temps. len = I ;}return temps;}/* operator char * () {return maxNum;} */CHugeInt & operator ++ = (int n) {CHugeInt temps (n ); * this = this-> operator + (temps); // cout <this-> maxNum <endl; return * this ;} friend ostream & operator <(ostream & OS, const CHugeInt & s) {int I = 0, j = s. len-1; // cout <"len:" <s. len <endl; // cout <"output:" <s. maxNum <endl; for (; j> = I; j --) OS <s. maxNum [j]; return OS;} friend CHugeInt operator + (int n, CHugeInt s) {CHugeInt temps (n); s = s + temps; return s ;} friend CHugeInt operator + (CHugeInt s, int n) {CHugeInt temps (n); s = s + temps; return s;} CHugeInt & operator ++ () {(* this) + = 1; // cout <"post-auto-increment:" <this-> maxNum <endl; return * (this );} CHugeInt operator ++ (int n) {CHugeInt temps; strcpy (temps. maxNum, maxNum); temps. len = len; this-> operator + = (1); // cout <temps. maxNum <endl; // cout <"len:" <temps. len <endl; return temps ;}; int main () {char s [210]; int n; while (cin> s> n) {CHugeInt a (s); CHugeInt B (n); cout <a + B <endl; cout <n + a <endl; cout <a + n <endl; B + = n; cout <++ B <endl; cout <B ++ <endl; cout <B <endl;} return 0 ;}