R进制高精度乘法
This commit is contained in:
parent
22afbc6dbb
commit
a5afa671a6
|
@ -0,0 +1,3 @@
|
|||
# 标题
|
||||
|
||||
* 内容
|
|
@ -0,0 +1,20 @@
|
|||
# R进制高精度乘法
|
||||
|
||||
题目描述
|
||||
计算R(2<=R<=36)进制下两个高精度数的乘法,这两个数的位数均不超过100位,并输出结果(R进制,A=10,B=11,C=12,......,Z=35),输入输出中涉及到的英文字母均为大写格式字母。
|
||||
|
||||
输入输出格式
|
||||
输入格式:
|
||||
三行,第一行,R。第二、三行分别为用字符串表达的两个高精度数。
|
||||
输出格式:
|
||||
一行,结果值。
|
||||
|
||||
输入输出样例
|
||||
输入样例#1:
|
||||
8
|
||||
3
|
||||
3
|
||||
输出样例#1:
|
||||
11
|
||||
提示信息
|
||||
直接以R进制进位进行运算。
|
|
@ -0,0 +1,6 @@
|
|||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello Easy C++ project!" << std::endl;
|
||||
}
|
Binary file not shown.
|
@ -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.
|
@ -0,0 +1,3 @@
|
|||
8
|
||||
3
|
||||
3
|
|
@ -0,0 +1,3 @@
|
|||
16
|
||||
88
|
||||
88
|
|
@ -0,0 +1,3 @@
|
|||
16
|
||||
A1A
|
||||
B2B
|
|
@ -0,0 +1,3 @@
|
|||
16
|
||||
2
|
||||
7
|
|
@ -0,0 +1,3 @@
|
|||
16
|
||||
1A
|
||||
1A
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue