标签:ems enum delete temp 逆序 printf pre oid cst
#include <cstdio> #include <cstring> #include <string> void reverseOrder(char* str, int p, int q) { char temp; while(p < q) { temp = str[p]; str[p] = str[q]; str[q] = temp; p ++; q --; } } char* multiLargeNum(char* A, char* B) { int m = strlen(A); int n = strlen(B); char* result = new char[m+n+1]; memset(result, ‘0‘, m+n); result[m+n] = ‘\0‘; reverseOrder(A, 0, m-1); reverseOrder(B, 0, n-1); int multiFlag; // 乘积进位 int addFlag; // 加法进位 for(int i=0; i <= n-1; i++) // B的每一位 { multiFlag = 0; addFlag = 0; for(int j=0; j <= m-1; j++) // A的每一位 { // ‘0‘ - 48 = 0 int temp1 = (A[j] - 48) * (B[i] - 48) + multiFlag; multiFlag = temp1 / 10; temp1 = temp1 % 10; int temp2 = (result[i+j] - 48) + temp1 + addFlag; addFlag = temp2 / 10; result[i+j] = temp2 % 10 + 48; } result[i + m] += multiFlag + addFlag; } reverseOrder(result, 0, m+n-1); // 逆序回来 return result; } int main() { char A[10000]; char B[10000]; scanf("%s%s",A,B); char *res = multiLargeNum(A, B); if(res[0] != 48) printf("%c", res[0]); printf("%s", res+1); printf("\n"); delete [] res; return 0; }
标签:ems enum delete temp 逆序 printf pre oid cst
原文地址:https://www.cnblogs.com/xiao-xue-di/p/9454246.html