有没有比较好的C/C++万能框架和模板?
#include <bits/stdc++.h>
using namespace std;
int main() {
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
return 0;
}
如果你喜欢用cin和cout的话可以用这个模板,让输入输出的速度提高好几倍。
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline void read(T &x) {
T a = 0, b = 1;
char ch;
while (ch != '-' && (ch < '0' || ch > '9')) {
ch = getchar();
}
if (ch == '-') {
b = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
a = ((T) a << 3) + ((T) a << 1) + (ch ^ '0');
ch = getchar();
}
x = a * b;
}
template<typename T> inline void write(T x, char c = '\0') {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) {
write(x / 10);
}
putchar(x % 10 + '0');
if (c != '\0') {
putchar(c);
}
}
int main() {
return 0;
}
这个是快读快写的,适用于整数类型变量(short, int, long, __int128, unsigned, signed)。
我看到有大神这么写。不知您是否喜欢。
// 此处写标题
#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265359
#endif // M_PI
#define endl "\n"
// 各种简写
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define GET(a, n) for (int __i = 0; __i < (n); ++__i) cin >> a[__i];
#define GETM(a, n, m) for (int __i = 0; __i < (n); ++__i) for (int __j = 0; __j < m; ++__j) cin >> a[__i][__j];
#define PRINTM(a, n, m) for (int __i = 0; __i < (n); ++__i) { for (int __j = 0; __j < m; ++__j) cout << a[__i][__j] << " "; cout << endl; };
#define PRINT(a, n) for (int __i = 0; __i < (n); ++__i) cout << a[__i] << " ";
#define IT(a) a.begin(), a.end()
#define SQR(x) (x) * (x)
#define CASE(a, s) cout << "Case #" << a << ": " << s << endl;
#define DEB(a) cout << #a << " = " << (a) << endl; cout.flush();
#define DEBA(a) for (auto __i: a) cout << __i << " "; cout << endl; cout.flush();
#define IFDEB(b, a) if (b) { cout << #a << " = " << (a) << endl; cout.flush(); }
using namespace std;
// 简写名称
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
typedef vector <vector <int>> VVI;
typedef pair <int, int> PII;
const int MOD = 1000000007;
template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; FOR(i, 0, n) sum += v[i]; return sum; }
// 加快输入输出速度
struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;
int main()
{
// 在此写代码
return 0;
}
同意Jerrywang2009
因为我是个初一学生,老师也推荐用bits/stdc++.h
// 标题
#include <bits/stdc++.h> // 万能头文件
using namespace std;
int main()
{
// 在这里写C++代码
return 0;
}
#include <bits/stdc++.h> //万能头
using namespace std;
//这里写全局变量和函数
int main(){
//这里写代码
return 0;
}