一、解题代码

 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 const int nmax = 500+5;
 5 int  a[nmax], b[nmax];
 6 char x[nmax], y[nmax];
 7 int  c[2*nmax+1];
 8 int main(){
 9     
10     while(cin>>x>>y){
11         memset(a, 0, sizeof(a));
12         memset(b, 0, sizeof(b));
13         memset(c, 0, sizeof(c));
14         if(x&&y==0){
15             cout<<'0';
16             return 0;
17         }
18         for(int i=strlen(x)-1, j=0; i>=0; i--,j++)
19             a[j] = x[i]-'0';
20         for(int i=strlen(y)-1, j=0; i>=0; i--,j++)
21             b[j] = y[i]-'0';
22         for(int i=0; i<strlen(x); i++){
23             for(int j=0; j<strlen(y); j++){
24                 c[i+j] += a[i]*b[j];
25             }
26         }
27         int i;
28         for(i=0; i<2*nmax; i++){
29             c[i+1] += c[i]/10;
30             c[i] %= 10; 
31         }
32         while(c[i]==0) i--;
33         for(;i>=0;i--)
34             cout<<c[i];
35     }    
36     return 0; 
37 } 

二、解题反思

  1、模拟乘法计算过程,进行进制处理。

  2、难点在于能否想到 i+j 位置的计算意义并将其位置上的数累加。

相关文章:

  • 2021-10-19
  • 2021-11-20
  • 2022-01-13
  • 2021-12-10
  • 2022-02-21
  • 2021-10-19
  • 2022-12-23
  • 2021-06-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
相关资源
相似解决方案