标签:字符串 class pre bsp 模拟 fine -- max span
// 加法 #define MAX_N 1000 string a, b; int A[MAX_N], B[MAX_N], C[MAX_N+1]; // A + B = C void solve(){ int lena = a.size(), lenb = b.size(); int j = 0; for (int i = lena - 1; i >=0; i--) A[j++] = a[i] - ‘0‘; j = 0; for (int i = lenb - 1; i >= 0; i--) A[j++] = a[i] - ‘0‘; int temp = 0; for (int i = 0; i < MAX_N; i++){ C[i] = A[i] + B[i] + temp; temp = C[i] / 10; C[i] = C[i] % 10; } int maxs = (lena, lenb) - 1; if (C[maxs + 1] != 0) maxs ++; for (int i = max; i >= 0; i--) cout << C[i]; }
标签:字符串 class pre bsp 模拟 fine -- max span
原文地址:https://www.cnblogs.com/astonc/p/10645921.html