R进制高精度乘法

This commit is contained in:
James 2020-03-25 12:08:18 +08:00
parent 22afbc6dbb
commit a5afa671a6
12 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1,20 @@
# R进制高精度乘法
题目描述
  计算R2<=R<=36进制下两个高精度数的乘法这两个数的位数均不超过100位并输出结果R进制A=10B=11C=12......Z=35输入输出中涉及到的英文字母均为大写格式字母。
输入输出格式
输入格式:
  三行第一行R。第二、三行分别为用字符串表达的两个高精度数。
输出格式:
  一行,结果值。
输入输出样例
输入样例#1
8
3
3
输出样例#1
11
提示信息
  直接以R进制进位进行运算。

View File

@ -0,0 +1,6 @@
#include <iostream>
int main()
{
std::cout << "Hello Easy C++ project!" << std::endl;
}

BIN
1771_systemnumby/main.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,43 @@
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
int n, a[101] = { 0 }, b[101] = { 0 }, c[201] = { 0 }, lena, lenb, lenc = 0;
string a1, b1;
cin >> n >> a1 >> b1;
lena = a1.size();
lenb = b1.size();
for (int i = 0; i < lena; i++) {
if (a1[i] >= 'A') {
a1[i] = a1[i] - 'A' + '9' + 1;
}
a[lena-i-1] = a1[i] - '0';
}
for (int i = 0; i < lenb; i++) {
if (b1[i] >= 'A') {
b1[i] = b1[i] - 'A' + '9' + 1;
}
b[lenb-1-i] = b1[i] - '0';
}
for (int i = 0; i < lena; i++) {
for (int j = 0; j < lenb; j++) {
c[i + j] += a[i] * b[j];
c[i + j + 1] += c[i + j] / n;
c[i + j] %= n;
}
}
int len = lena + lenb;
while(c[len-1]==0&&len>0){
len--;
}
while (len > 0) {
--len;
if (c[len] > 9) {
char c1 = c[len] - 10 + 'A';
cout << c1;
} else {
cout << c[len];
}
}
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
8
3
3

View File

@ -0,0 +1,3 @@
16
88
88

View File

@ -0,0 +1,3 @@
16
A1A
B2B

View File

@ -0,0 +1,3 @@
16
2
7

View File

@ -0,0 +1,3 @@
16
1A
1A

View File

@ -0,0 +1,30 @@
## z:\Chao\src\1771_systemnumby\test\in.txt
2020/03/24 Öܶþ 13:43:26.46
11
-----------------------------------------------
Process exited after 160 ms with return value 0
## z:\Chao\src\1771_systemnumby\test\in2.txt
2020/03/24 Öܶþ 13:43:26.46
4840
-----------------------------------------------
Process exited after 90 ms with return value 0
## z:\Chao\src\1771_systemnumby\test\in3.txt
2020/03/24 Öܶþ 13:43:26.46
70D05E
-----------------------------------------------
Process exited after 90 ms with return value 0
## z:\Chao\src\1771_systemnumby\test\in4.txt
2020/03/24 Öܶþ 13:43:26.46
E
-----------------------------------------------
Process exited after 80 ms with return value 0
## z:\Chao\src\1771_systemnumby\test\in5.txt
2020/03/24 Öܶþ 13:43:26.46
2A4
-----------------------------------------------
Process exited after 80 ms with return value 0