你猜
作者:
吴子涵
,
2021-07-31 10:57:00
,
所有人可见
,
阅读 290
#include <bits/stdc++.h>
using namespace std;
vector<int> add(vector<int> &A, vector<int> &B) // C = A + B, A >= 0, B >= 0
{
if (A.size() < B.size()) return add(B, A);
vector<int> C;
int t = 0;
for (int i = 0; i < A.size(); i ++ )
{
t += A[i];
if (i < B.size()) t += B[i];
C.push_back(t % 10);
t /= 10;
}
if (t) C.push_back(t);
return C;
}
vector<int> sub(vector<int> &A, vector<int> &B) // C = A - B, 满足A >= B, A >= 0, B >= 0
{
vector<int> C;
for (int i = 0, t = 0; i < A.size(); i ++ )
{
t = A[i] - t;
if (i < B.size()) t -= B[i];
C.push_back((t + 10) % 10);
if (t < 0) t = 1;
else t = 0;
}
while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
int main()
{
vector<int> a,s,u,p;
for(int i=1; i<=100000; i++)
a.push_back(i);
srand(time(0));
random_shuffle(a.begin(),a.end());
for(int i=1; i<=50; i++)
{
if(i==50)cout<<a[i];
else cout<<a[i]<<"+";
u.push_back(a[i]);
reverse(s.begin(),s.end());
reverse(u.begin(),u.end());
s=add(s,u);
reverse(s.begin(),s.end());
u=p;
}
cout<<endl;
for(int i=0; i<s.size(); i++)cout<<s[i];
return 0;
}
返回的是结果
大家请误踩,这是我们团队的测试数据生成器(捂脸)