程序代码:
#include <stdio.h> #include <string.h> char* foo( const char* a, const char* b, char c[static 200001] ) { memset( c, 0, 200001 ); const size_t alen = strlen(a); const size_t blen = strlen(b); for( size_t ai=0; ai!=alen; ++ai ) { unsigned carry = 0; for( size_t bi=0; bi!=blen; ++bi ) { carry += c[200000-ai-bi-1] + (a[alen-ai-1]-'0')*(b[blen-bi-1]-'0'); c[200000-ai-bi-1] = carry % 10; carry /= 10; } if( carry != 0 ) c[200000-ai-blen-1] = carry; } char* p = &c[200000-1]; for( size_t i=0; i!=200000; ++i ) { c[i] += '0'; if( p==&c[200000-1] && c[i]!='0' ) p = c+i; } return p; } int main( void ) { //{ // test // char c[200001]; // printf( "%s\n", foo("0","0",c) ); // printf( "%s\n", foo("0","123",c) ); // printf( "%s\n", foo("123","0",c) ); // printf( "%s\n", foo("999","99",c) ); // 98901 // printf( "%s\n", foo("999","999",c) ); // 998001 // printf( "%s\n", foo("86420","9753111111",c) ); // 842863862212620 //} char a[100001], b[100001], c[200001]; scanf( "%s%s", a, b ); printf( "%s\n", foo(a,b,c) ); return 0; }