'commit'
This commit is contained in:
26
TangDou/AcWing/HighPrecision/Backup/791_add1.cpp
Normal file
26
TangDou/AcWing/HighPrecision/Backup/791_add1.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 100010;
|
||||
int a[N], al;
|
||||
int b[N], bl;
|
||||
|
||||
void add(int a[], int &al, int b[], int &bl) {
|
||||
int t = 0;
|
||||
al = max(al, bl);
|
||||
for (int i = 1; i <= al; i++) {
|
||||
t += a[i] + b[i];
|
||||
a[i] = t % 10;
|
||||
t /= 10;
|
||||
}
|
||||
if (t) a[++al] = 1;
|
||||
}
|
||||
int main() {
|
||||
string x, y;
|
||||
cin >> x >> y;
|
||||
for (int i = x.size() - 1; i >= 0; i--) a[++al] = x[i] - '0';
|
||||
for (int i = y.size() - 1; i >= 0; i--) b[++bl] = y[i] - '0';
|
||||
add(a, al, b, bl);
|
||||
for (int i = al; i; i--) printf("%d", a[i]);
|
||||
return 0;
|
||||
}
|
||||
36
TangDou/AcWing/HighPrecision/Backup/792_sub1.cpp
Normal file
36
TangDou/AcWing/HighPrecision/Backup/792_sub1.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int N = 1e5 + 10;
|
||||
int a[N], al;
|
||||
int b[N], bl;
|
||||
|
||||
void sub(int a[], int &al, int b[], int &bl) {
|
||||
int t = 0;
|
||||
al = max(al, bl);
|
||||
for (int i = 1; i <= al; i++) {
|
||||
t = a[i] - b[i] - t;
|
||||
a[i] = (t + 10) % 10;
|
||||
t < 0 ? t = 1 : t = 0;
|
||||
}
|
||||
while (al > 1 && a[al] == 0) al--;
|
||||
}
|
||||
|
||||
int main() {
|
||||
string x, y;
|
||||
cin >> x >> y;
|
||||
|
||||
// 负号
|
||||
if (x.size() < y.size() || (x.size() == y.size() && x < y)) {
|
||||
printf("-");
|
||||
swap(x, y);
|
||||
}
|
||||
|
||||
for (int i = x.size() - 1; i >= 0; i--) a[++al] = x[i] - '0';
|
||||
for (int i = y.size() - 1; i >= 0; i--) b[++bl] = y[i] - '0';
|
||||
|
||||
sub(a, al, b, bl);
|
||||
|
||||
for (int i = al; i >= 1; i--) printf("%d", a[i]);
|
||||
return 0;
|
||||
}
|
||||
32
TangDou/AcWing/HighPrecision/Backup/793_mul_big.cpp
Normal file
32
TangDou/AcWing/HighPrecision/Backup/793_mul_big.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e5 + 10;
|
||||
int a[N], al;
|
||||
int b[N], bl;
|
||||
void mul(int a[], int &al, int b[], int &bl) {
|
||||
int t = 0;
|
||||
int c[N] = {0};
|
||||
for (int i = 1; i <= al; i++)
|
||||
for (int j = 1; j <= bl; j++)
|
||||
c[i + j - 1] += a[i] * b[j];
|
||||
al += bl;
|
||||
for (int i = 1; i <= al; i++) {
|
||||
t += c[i];
|
||||
a[i] = t % 10;
|
||||
t /= 10;
|
||||
}
|
||||
// 前导0
|
||||
while (al > 1 && a[al] == 0) al--;
|
||||
}
|
||||
|
||||
int main() {
|
||||
string x, y;
|
||||
cin >> x >> y;
|
||||
for (int i = x.size() - 1; i >= 0; i--) a[++al] = x[i] - '0';
|
||||
for (int i = y.size() - 1; i >= 0; i--) b[++bl] = y[i] - '0';
|
||||
|
||||
mul(a, al, b, bl);
|
||||
for (int i = al; i; i--) printf("%d", a[i]);
|
||||
return 0;
|
||||
}
|
||||
27
TangDou/AcWing/HighPrecision/Backup/793_mul_int.cpp
Normal file
27
TangDou/AcWing/HighPrecision/Backup/793_mul_int.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 1e5 + 10;
|
||||
int a[N], al;
|
||||
|
||||
void mul(int a[], int &al, int b) {
|
||||
int t = 0;
|
||||
for (int i = 1; i <= al; i++) {
|
||||
t += a[i] * b;
|
||||
a[i] = t % 10;
|
||||
t /= 10;
|
||||
}
|
||||
if (t) a[++al] = t;
|
||||
while (al > 1 && a[al] == 0) al--;
|
||||
}
|
||||
|
||||
int main() {
|
||||
string x;
|
||||
int y;
|
||||
cin >> x >> y;
|
||||
for (int i = x.size() - 1; i >= 0; i--) a[++al] = x[i] - '0';
|
||||
mul(a, al, y);
|
||||
for (int i = al; i; i--) printf("%d", a[i]);
|
||||
return 0;
|
||||
}
|
||||
35
TangDou/AcWing/HighPrecision/Backup/794_div_int.cpp
Normal file
35
TangDou/AcWing/HighPrecision/Backup/794_div_int.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int N = 1e5 + 10;
|
||||
|
||||
int a[N];
|
||||
int al, r;
|
||||
|
||||
void div(int a[], int &al, int b, int &r) {
|
||||
r = 0;
|
||||
for (int i = al; i >= 1; i--) {
|
||||
r = r * 10 + a[i];
|
||||
a[i] = r / b;
|
||||
r %= b;
|
||||
}
|
||||
// 去前导0
|
||||
while (al > 1 && !a[al]) al--;
|
||||
}
|
||||
|
||||
int main() {
|
||||
string x;
|
||||
int y;
|
||||
|
||||
cin >> x >> y;
|
||||
|
||||
for (int i = x.size() - 1; i >= 0; i--) a[++al] = x[i] - '0';
|
||||
// 高精度除法
|
||||
div(a, al, y, r);
|
||||
|
||||
// 输出
|
||||
for (int i = al; i; i--) printf("%d", a[i]);
|
||||
puts("");
|
||||
printf("%d\n", r);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user