JSON{
"C++ Template": {
"prefix": "#include",
"body": [
"//程序算法:$0",
"#include <bits/stdc++.h>",
"",
"namespace IO{",
" void file() {",
" freopen(\"input.in\", \"r\", stdin);",
" freopen(\"output.out\", \"w\", stdout);",
" }",
"",
" #define gc getchar",
" #define pc putchar",
"",
" template <typename T>",
" inline void read(T &x) {",
" x = 0;",
" bool f = 0;",
" T s = 1;",
" char ch = gc();",
" while (!isdigit(ch) && ~ch) {",
" f = (ch == '-');",
" ch = gc();",
" }",
"",
" while (isdigit(ch)) {",
" x = x * 10 + (ch - 48);",
" ch = gc();",
" }",
"",
" if (ch == '.') {",
" ch = gc();",
" while (isdigit(ch)) {",
" s *= 0.1;",
" x += (ch - 48) * s;",
" ch = gc();",
" }",
" }",
" if (f) x = -x;",
" }",
"",
" template <typename T>",
" inline void write(T x) {",
" if (x < 0) {",
" pc('-');",
" x = -x;",
" }",
"",
" if (x >= 10) write(x / 10);",
" pc(x % 10 + 48);",
" }",
"",
" using std::string;",
" inline void read(string &s) {",
" s.clear();",
" char ch = gc();",
" while (isspace(ch)) ch = gc();",
" while (!isspace(ch) && ~ch) s += ch, ch = gc();",
" }",
"",
" inline void read(char &ch) {",
" ch = gc();",
" while (isspace(ch)) ch = gc();",
" }",
"",
" inline void write(const string s) {",
" for (auto ch : s) pc(ch);",
" }",
"",
" inline void write(const char ch) {",
" pc(ch);",
" }",
"",
" inline void write(const double x) {",
" printf(\"%.3Lf\", (long double)x);",
" }",
"",
" inline void write(const char *s) {",
" while (*s) pc(*(s++));",
" }",
"",
" template <typename T, typename ...t>",
" inline void read(T &x, t &...y) {",
" read(x);",
" read(y...);",
" }",
"",
" template <typename T, typename ...t>",
" inline void write(T x, t ...y) {",
" write(x);",
" write(y...);",
" }",
"}",
"",
"using namespace IO;",
"using namespace std;",
"",
"int main() {",
" ",
" return 0;",
"}"
],
"description": "My C++ Template"
},
"BigInteger": {
"prefix": "Class_BigInteger",
"body": [
"struct BigInteger{",
" static const int BASE = 100000000;",
" static const int WIDTH = 8;",
" vector<int> num;",
"",
" BigInteger(long long x = 0) {*this = x;}",
"",
" BigInteger operator = (long long x) {",
" num.clear();",
" do {",
" num.push_back(x % BASE);",
" x /= BASE;",
" }while (x > 0);",
" return *this;",
" }",
"",
" BigInteger operator = (const string& str) {",
" num.clear();",
" int x, len = (str.size() - 1) / WIDTH + 1;",
" for (int i = 0; i < len; i++) {",
" int end = str.size() - i * WIDTH;",
" int start = max(0, end - WIDTH);",
" sscanf(str.substr(start, end - start).c_str(), \"%d\", &x);",
" num.push_back(x); ",
" }",
" return *this;",
" }",
"",
" BigInteger operator + (const BigInteger& b) const {",
" BigInteger c;",
" c.num.clear();",
" for (int i = 0, g = 0; ; i++) {",
" if (g == 0 && i >= num.size() && i >= b.num.size()) break;",
" int x = g;",
" if (i < num.size()) x += num[i];",
" if (i < b.num.size()) x += b.num[i];",
" c.num.push_back(x % BASE);",
" g = x / BASE;",
" }",
" return c;",
" }",
"",
" BigInteger operator += (const BigInteger& b) {",
" *this = (*this + b);",
" return *this;",
" }",
"",
" //使用前确认a > b",
" BigInteger operator - (const BigInteger& b) const {",
" BigInteger c;",
" c.num.clear();",
" for (int i = 0, g = 0; ; i++) {",
" if (g == 0 && i >= num.size() && i >= b.num.size()) break;",
" int x = num[i] - g;",
" if (i < b.num.size()) x -= b.num[i];",
" if (x < 0) x += BASE, g = 1;",
" else g = 0;",
" c.num.push_back(x);",
" }",
" return c;",
" }",
"",
" BigInteger operator -= (const BigInteger& b) {",
" *this = (*this - b);",
" return *this;",
" }",
"",
" BigInteger operator * (const long long& b) const {",
" BigInteger c;",
" c.num.clear();",
" long long g = 0;",
" for (int i = 0; ; i++) {",
" if (g == 0 && i >= num.size()) break;",
" long long x = g;",
" if (i < num.size()) x += num[i] * b;",
" c.num.push_back(x % BASE);",
" g = x / BASE;",
" }",
" return c;",
" }",
"",
" BigInteger operator *= (const long long& b) {",
" *this = (*this * b);",
" return *this;",
" }",
"",
" BigInteger operator * (const BigInteger& b) const {",
" BigInteger c;",
" c.num.assign(num.size() + b.num.size(), 0);",
" for (int i = 0; i < num.size(); i++) {",
" long long g = 0;",
" for (int j = 0; j < b.num.size() || g; j++) {",
" long long x = c.num[i + j] + 1LL * num[i] * (j < b.num.size() ? b.num[j] : 0) + g;",
" c.num[i + j] = x % BASE;",
" g = x / BASE;",
" }",
" }",
" // 去除前导零",
" while (c.num.size() > 1 && c.num.back() == 0) c.num.pop_back();",
" return c;",
" }",
"",
" BigInteger operator *= (const BigInteger& b) {",
" *this = (*this * b);",
" return *this;",
" }",
" ",
" BigInteger operator / (const long long& b) const {",
" BigInteger c;",
" c.num.resize(num.size());",
" long long r = 0;",
" for (int i = num.size() - 1; i >= 0; i--) {",
" long long x = num[i] + r * BASE;",
" c.num[i] = x / b;",
" r = x % b;",
" }",
" // 去除前导零",
" while (c.num.size() > 1 && c.num.back() == 0) c.num.pop_back();",
" return c;",
" }",
"",
" BigInteger operator /= (const long long& b) {",
" *this = (*this / b);",
" return *this;",
" }",
"",
" BigInteger operator << (const long long& b) { // Very important: (1 << b) should in long long ",
" return *this * (1LL << b);",
" }",
"",
" BigInteger operator <<= (const long long& b) {",
" *this = (*this << b);",
" return *this;",
" }",
"",
" BigInteger operator >> (const long long& b) { // Very important: (1 << b) should in long long ",
" return *this / (1LL << b);",
" }",
"",
" BigInteger operator >>= (const long long& b) {",
" *this = (*this >> b);",
" return *this;",
" }",
" ",
" int count_zero() {",
" if (*this == BigInteger(0)) {",
" return 0;",
" }",
" int count = 0;",
" BigInteger tmp = *this;",
" while (true) {",
" int last_digit = tmp.num[0] % 10; // 获取最低位的十进制数字",
" if (last_digit % 2 != 0) { // 判断是否为偶数",
" break;",
" }",
" tmp /= 2LL; // 除以2",
" count++;",
" if (tmp == BigInteger(0)) { // 防止除以2后结果为0",
" break;",
" }",
" }",
" return count;",
" }",
"",
" bool operator < (const BigInteger& b) const {",
" if (num.size() != b.num.size()) return num.size() < b.num.size();",
" for (int i = num.size() - 1; i >= 0; i--)",
" if (num[i] != b.num[i]) return num[i] < b.num[i];",
" return false;",
" }",
"",
" bool operator > (const BigInteger& b) const {",
" return b < *this;",
" }",
"",
" bool operator <= (const BigInteger& b) const {",
" return !(b < *this);",
" }",
"",
" bool operator >= (const BigInteger& b) const {",
" return !(*this < b);",
" }",
"",
" bool operator != (const BigInteger& b) const {",
" return b < *this || *this < b;",
" }",
"",
" bool operator == (const BigInteger& b) const {",
" return !(b < *this) && !(*this < b);",
" }",
"",
" void print() {",
" printf(\"%d\", num.back());",
" for (int i = num.size() - 2; i >= 0; i--) {",
" printf(\"%d\", num[i]);",
" }",
" }",
"};"
],
"description": "A BigInteger struct."
},
"Matrix": {
"prefix": "Class_Matrix",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"",
"struct Matrix{",
" static const int MAXN = 1e4 + 10;",
"",
" int a[MAXN][MAXN];",
" int n, m;",
" Matrix(int n = 0, int m = 0) : n(n), m(m) {}",
" Matrix(int b[MAXN][MAXN], int n, int m) {",
" for (int i = 1; i <= n; i++) {",
" for (int j = 1; j <= m; j++) {",
" a[i][j] = b[i][j];",
" }",
" }",
" }",
"",
" Matrix operator = (const Matrix& b) {",
" n = b.n, m = b.m;",
" for (int i = 1; i <= n; i++) {",
" for (int j = 1; j <= m; j++) {",
" a[i][j] = b.a[i][j];",
" }",
" }",
" return *this;",
" }",
"",
" Matrix operator + (const Matrix& b) const {",
" if (n != b.n && m != b.m) assert(0 && \"Matrix operator + Error!\");",
" Matrix c(n, m);",
" for (int i = 1; i <= n; i++) {",
" for (int j = 1; j <= m; j++) {",
" c.a[i][j] = a[i][j] + b.a[i][j];",
" }",
" }",
" return c;",
" }",
"",
" Matrix operator += (const Matrix& b) {",
" *this = *this + b;",
" return *this;",
" }",
"",
" Matrix operator - (const Matrix& b) const {",
" if (n != b.n && m != b.m) assert(0 && \"Matrix operator - Error!\");",
" Matrix c(n, m);",
" for (int i = 1; i <= n; i++) {",
" for (int j = 1; j <= m; j++) {",
" c.a[i][j] = a[i][j] - b.a[i][j];",
" }",
" }",
" return c;",
" }",
"",
" Matrix operator -= (const Matrix& b) {",
" *this = *this - b;",
" return *this;",
" }",
"",
" Matrix operator * (const int& b) const {",
" Matrix c(n, m);",
" for (int i = 1; i <= n; i++) {",
" for (int j = 1; j <= m; j++) {",
" c.a[i][j] = b * a[i][j];",
" }",
" }",
" }",
"",
" Matrix operator *= (const int& b) {",
" *this = *this * b;",
" return *this;",
" }",
"",
" Matrix operator * (const Matrix& b) const {",
" if (m != b.n) assert(0 && \"Matrix operator * Error!\"); ",
" Matrix c(n, b.m);",
" for (int i = 1; i <= n; i++) {",
" for (int j = 1; j <= b.m; j++) {",
" c.a[i][j] = 0;",
" for (int k = 1; k <= m; k++) {",
" c.a[i][j] += a[i][k] * b.a[k][j];",
" }",
" }",
" }",
" return c;",
" }",
"",
" Matrix operator *= (const Matrix& b) {",
" *this = *this * b;",
" return *this;",
" }",
"};"
],
"description": ""
}
}