Zlc晨鑫 @ 2020-03-24 11:45:19
输入输出运算符重载CE
,这是为什么啊?
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define maxn 5000 + 5
using namespace std;
struct INT {
vector<int> v;
INT(int x = 0) {
this->v.push_back(x);
}
int& operator [](int i) {
return this->v.at(i);
}
int size() {
return this->v.size();
}
void push_back(int i) {
this->v.push_back(i);
}
INT operator +(INT b) {
INT a = (*this), c;
int x = 0;
for (int i = 0, len = min(a.size(), b.size()); i < len; i++) {
c.push_back(a[i] + b[i] + x);
x = c[i] / 10;
c[i] %= 10;
}
while (c.size() <= a.size()) c.push_back(a[c.size()]);
while (c.size() <= b.size()) c.push_back(b[c.size()]);
}
istream& operator >>(istream& in) {
string s;
in >> s;
for (int i = s.size() - 1; i >= 0; i--)
a.push_back(s.at(i) - '0');
return in;
}
ostream& operator <<(ostream& out) {
for (int i = this->v.size() - 1; i >= 0; i--)
out << v.at(i);
return out;
}
}f[maxn] = {0, 1, 2};
int main() {
int n;
cin >> n;
for (int i = 3; i <= n; i++) {
f[i] = f[i - 1] + f[i - 2];
}
cout << f[n] << '\n';
return 0;
}
by Zlc晨鑫 @ 2020-03-24 11:46:49
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define maxn 5000 + 5
using namespace std;
struct INT {
vector<int> v;
INT(int x = 0) {
this->v.push_back(x);
}
int& operator [](int i) {
return this->v.at(i);
}
int size() {
return this->v.size();
}
void push_back(int i) {
this->v.push_back(i);
}
INT operator +(INT b) {
INT a = (*this), c;
int x = 0;
for (int i = 0, len = min(a.size(), b.size()); i < len; i++) {
c.push_back(a[i] + b[i] + x);
x = c[i] / 10;
c[i] %= 10;
}
while (c.size() <= a.size()) c.push_back(a[c.size()]);
while (c.size() <= b.size()) c.push_back(b[c.size()]);
}
istream& operator >>(istream& in) {
string s;
in >> s;
for (int i = s.size() - 1; i >= 0; i--)
this->v.push_back(s.at(i) - '0');
return in;
}
ostream& operator <<(ostream& out) {
for (int i = this->v.size() - 1; i >= 0; i--)
out << v.at(i);
return out;
}
}f[maxn] = {0, 1, 2};
int main() {
int n;
cin >> n;
for (int i = 3; i <= n; i++) {
f[i] = f[i - 1] + f[i - 2];
}
cout << f[n] << '\n';
return 0;
}
by AFOing @ 2020-03-24 11:47:37
你把错误编译信息搞上来
by MY(一名蒟蒻) @ 2020-03-24 11:47:45
%%%
by MY(一名蒟蒻) @ 2020-03-24 11:48:00
您真的是啥都会
by liqingyang @ 2020-03-24 11:48:15
@Zlc晨鑫 编译信息?
by Zlc晨鑫 @ 2020-03-24 11:48:25
@AFOing 太多了
by liqingyang @ 2020-03-24 11:48:39
@MY(一名蒟蒻) 用重载运算符不是很正常嘛
by MY(一名蒟蒻) @ 2020-03-24 11:48:55
不过这题直接粘高精模板朴素算法就可以了呀
by liqingyang @ 2020-03-24 11:49:39
@MY(一名蒟蒻) 对滴,但是他不喜欢,我也没办法。。。
by dingcx @ 2020-03-24 11:51:13
CE 还求助?