高精度除与高精度

来源:百度知道 编辑:UC知道 时间:2024/06/01 23:50:14
Problem H:高精度 除以 高精度

Time Limit:1000MS Memory Limit:65536K
Total Submit:33 Accepted:17

Description

高精度除以高精度。

Input

有很多组测试数据。
每行两个整数A、B:
其中A、B长度都不超过100,用空格隔开。
A>=0 && B>0。
没有前导“+”号。

Output

每行输出两个数C、D,去掉前导0。
用一个空格隔开。
其中,C=A/B;D=A%B;

Sample Input

12 03
12 7
12 1

Sample Output

4 0
1 5
12 0

呵呵。。。。

#include <stdio.h>
#include <string>

#define MAXCHAR 20000

void Add (char *ch1 , char *ch2 , char *ch3)
{
int len1 = strlen (ch1) , len2 = strlen (ch2) , len3 , i , tmp , num1[MAXCHAR] , num2[MAXCHAR] , num3[MAXCHAR];
memset (num1 , 0 , sizeof(num1));
memset (num2 , 0 , sizeof(num2));
memset (num3 , 0 , sizeof(num3));

for (i=len1-1;i>=0;i--) num1[len1-1-i] = ch1[i] - 48; for (i=len2-1;i>=0;i--) num2[len2-1-i] = ch2[i] - 48;

i = 0 , tmp = 0 , len3 = len1 > len2 ? len1 : len2;
while (i < len3)
{
num3[i] = num1[i] + num2[i] + tmp;
tmp = 0;
if (num3[i] >= 10) { tmp = num3[i]/10; num3[i] %= 10; }
i ++;
}
if (tmp != 0) { num3[i] = tmp; i ++; }
len3 = i;
for (i=len3-1;i>=0;i--) ch3[len3-1-i] = num3[i] + 48;
ch3[len3] = '\0';
return ;
}

void Minus (char *ch1