这个相较于加法和减法要稍微复杂点(但也挺弱智的),还是那句话,回到小学,算一下竖式,模拟一下乘的过程。
Code
#include<bits/stdc++.h>
using namespace std
;
int a
[300],b
[300],c
[1000000];
string s1
,s2
;
int main()
{
cin
>>s1
; cin
>>s2
;
int len1
=s1
.size();
int len2
=s2
.size();
for(int i
=1;i
<=len1
;i
++) a
[i
]=s1
[len1
-i
]-'0';
for(int i
=1;i
<=len2
;i
++) b
[i
]=s2
[len2
-i
]-'0';
for(int j
=1;j
<=len2
;j
++)
{
for(int i
=1;i
<=len2
;i
++)
{
c
[j
-1+i
]+=a
[i
]*b
[j
];
c
[j
-1+i
+1]+=c
[j
-1+i
]/10;
c
[j
-1+i
]%=10;
}
}
int len
=len1
+len2
;
while(c
[len
]==0&&len
>=2) len
--;
for(int i
=len
;i
>=1;i
--) printf("%d",c
[i
]);
return 0;
}
学习厌倦了?点我有更多精彩哦!
转载请注明原文地址: https://mac.8miu.com/read-506378.html