1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| #include<iostream> using namespace std; int a[300] = {}, b[300] = {}, c[300] = {}, tmp[300] = {};
void strReverseToInt(string str,int dec[]) { dec[0] = str.size(); for (int i = 1; i <= str.size(); i++) { dec[dec[0]-i+1] = str[i-1]-'0'; } } void printReverse(int *dec) { while (dec[0] > 0 && dec[dec[0]] == 0) { dec[0]--; } for (int i = dec[0]; i >= 1; i--) { cout << dec[i]; } } int* addstring(string s1, string s2) { strReverseToInt(s1, a); strReverseToInt(s2, b); c[0] = max(a[0], b[0]) + 1; for (int i = 1; i <= c[0]; i++) { c[i] = a[i] + b[i] + c[i]; c[i + 1] = c[i] / 10; c[i] %= 10; } return c; }
int* minu(string s1, string s2) { if (s1<s2) { s1.swap(s2); cout << "-"; } strReverseToInt(s1, a); strReverseToInt(s2, b); c[0] = max(a[0],b[0]); for (int i = 1; i <= c[0]; i++) { if (a[i]<b[i] ) { c[i] += 10; c[i + 1]--; } c[i] = a[i] - b[i]; } return c; }
int* multiply(string s1, string s2) { strReverseToInt(s1, a); strReverseToInt(s2, b); c[0] = a[0]+b[0]; for (int i = 1; i <= a[0]; i++) { for (int j = 1; j <= b[0]; j++) { c[i + j - 1] += (a[i] * b[j])%10; c[i + j] += c[i + j - 1] / 10; c[i + j - 1] %= 10; } } return c; }
void numcpy(int p[],int q[],int num) { q[0] = p[0] + num; for (int i = 1; i <=p[0]; i++) { q[i+num] = p[i]; } }
int compare(int x[], int y[]) { if (x[0] > y[0]) return 1; if (x[0] < y[0]) return -1; for (int i = x[0]; i > 0; i--) { if (x[i] > y[i]) return 1; if (x[i] < y[i]) return -1; } return 0; }
void minu(int a[], int b[]) { for (int i = 1; i <= a[0]; i++) { if (a[i] < b[i]) { a[i + 1]--; a[i] += 10; } a[i] -= b[i]; } while (a[a[0]] == 0 && a[0] > 0) { a[0]--; } }
int* divide(string s1, string s2) { strReverseToInt(s1, a); strReverseToInt(s2, b); c[0] = a[0]-b[0]+1; for (int i = c[0]; i >= 1; i--) { numcpy(b, tmp, i - 1); while (compare(a,tmp)>=0) { minu(a, tmp); c[i]++; } } return c; } int main() { string s1, s2; cin >> s1 >> s2; return 0; }
|