Zlc晨鑫 @ 2020-03-26 09:52:22
最后两个点WA
了,求助……
#include <string>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
istream& operator >> (istream& in, vector<int>& a) {
string A;
in >> A;
for (int i = A.size() - 1; i >= 0; --i) a.push_back(A[i] - '0');
return in;
}
ostream& operator << (ostream& out, const vector<int>& a) {
for (int i = a.size() - 1; i >= 0; --i)
out << a[i];
return out;
}
vector<int> operator * (const vector<int>& a, const vector<int>& b) {
vector<int> c;
for (int i = 0; i < b.size(); i++) {
vector<int> f(i, 0);
int t = 0;
for (int j = 0; j < a.size(); j++) {
f.push_back(a[j] * b[i] + t);
t = f[j + i] / 10;
f[j + i] %= 10;
}
if (t) f.push_back(t);
t = 0;
vector<int> y;
for (int j = 0; j < c.size(); j++) {
y.push_back(c[j] + f[j] + t);
t = y[j] / 10;
y[j] %= 10;
}
for (int j = c.size(); j < f.size(); j++)
y.push_back(f[j] + t), t = y[j] / 10, t %= 10;
if (t) y.push_back(t);
c = y;
}
int h;
for (h = c.size() - 1; !c[h] && h > 0; --h);
c.resize(h + 1);
return c;
}
int main() {
vector<int> a, b, c;
cin >> a >> b;
cout << a * b << '\n';
return 0;
}
by MY(一名蒟蒻) @ 2020-03-26 10:28:05
不是跟您说了用朴素算法吗···
by tidongCrazy @ 2020-03-26 11:33:36
py 他不香吗
by WanderingTrader @ 2020-03-29 17:06:44
字符串解决了,不用 重定义