SR_star @ 2023-11-25 17:39:33
用的自写的字符串加法和乘法
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
namespace str {
[[nodiscard]] bool isAllZeroString(const string &str) {
bool flag = true;
for (auto &ch : str) {
flag &= (ch == '0');
if (!flag) {
break;
}
}
return flag;
}
void operator+=(string &str0, string str1) {
ll sz0 = str0.size(), sz1 = str1.size();
for (ll i = sz0; i < sz1; ++i) {
str0.insert(str0.begin(), str1[0]);
str1.erase(str1.begin());
}
if (sz0 < sz1) {
reverse(str0.begin(), str0.begin() + sz1 - sz0);
}
if (str::isAllZeroString(str1)) {
return;
}
for (auto str0Iter = str0.rbegin(), str1Iter = str1.rbegin();
str0Iter != str0.rend() && str1Iter != str1.rend();
++str0Iter, ++str1Iter) {
ll sum = (*str0Iter ^ 48) + (*str1Iter ^ 48);
if (sum < 10) {
*str0Iter = char(sum ^ 48);
} else {
*str0Iter = char((sum % 10) ^ 48);
++str0Iter;
*str0Iter = char((sum / 10) ^ 48);
}
}
}
} // namespace str
void operator*=(string &str, const ll &n) {
if (n == 0) {
str.clear();
str.push_back('0');
}
if (n > 9) {
string temp{str};
temp *= (n % 10);
str *= (n / 10);
str.push_back('0');
str::operator+=(str, temp);
return;
}
for (ll i = str.size() - 1; i >= 0; --i) {
ll ans = (str.begin()[i] ^ 48) * n;
if (ans <= 9) {
str.begin()[i] = char(ans ^ 48);
} else {
str.begin()[i] = char(ans / 10 ^ 48);
str.push_back(char(ans % 10 ^ 48));
}
}
}
[[nodiscard]] string f(ll n) {
string ans{'1'};
for (; n; --n) {
ans *= n;
}
return ans;
}
[[nodiscard]] string x(ll n) {
string ans{'0'};
for (; n; --n) {
str::operator+=(ans, f(n));
}
return ans;
}
int main(void) {
ll n;
cin >> n;
cout << x(n) << '\n';
}
by leo_messi10 @ 2023-11-26 20:40:38
zhiyingnitaimei
by kongkongruye @ 2023-12-06 18:40:46
你你你,你这样写呀?!这么多!!!怪不得0分啊!这样吧,你关我,我给你找到了个大神仙!!!我把他(她)推你,好吧?