欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【高精乘单精】岛屿的缘分

程序员文章站 2022-07-15 12:47:27
...

【高精乘单精】岛屿的缘分


思路:

裸的高精乘单精


CodeCode:

#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]);//倒叙输出
}
相关标签: 高精度