【高精乘单精】岛屿的缘分
程序员文章站
2022-07-15 12:47:27
...
思路:
裸的高精乘单精
:
#include <cstdio>
#include <iostream>
#define CWH using
#define AK namespace
#define IOI std
CWH AK IOI;
char x[500],y[500];
int k,a[500],b[500],ans[500],g;
int main ()
{
//freopen("b.in","r",stdin);freopen("b.out","w",stdout);
scanf("%s%s%d",x,y,&k);
int len1 = strlen(x),len2 = strlen(y);
for (int i = 0; i < len1; ++i) a[len1 - i] = x[i] - '0'; //倒置
for (int i = 0; i < len2; ++i) b[len2 - i] = y[i] - '0';
for (int i = 1; i <= len1; ++i)
{
g = 0;
for (int j = 1; j <= len2; ++j)
{
ans[i + j - 1] = ans[i + j - 1] + a[i] * b[j] + g;
g = ans[i + j - 1] / 10;
ans[i + j - 1] %= 10;//高精乘
}
ans[i + len2] = g;
}
for (int i = k; i >= 1; --i)
printf("%d",ans[i]);//倒叙输出
}
推荐阅读