众所周知,C++标准库中cin/cout的效率及其令人捉急,所以今天为大家带来C++的in/out 优化
#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#endif
#define INF 0x3f3f3f3f
#define N 100005
#define ll long long
#define ull unsigned long long
#define il inline
#define rg register
using namespace std;
class Qin
{
inline ll read()
{
rg ll x(0);
rg bool w(1);
rg char ch(0);
while (!isdigit(ch))
{
if (ch == '-')
w = -1;
ch = getchar();
}
while (isdigit(ch))
{
x = (x << 3) + (x << 1) + (ch - '0');
ch = getchar();
}
return x * w;
}
bool getline;
public:
//字符串整行读入开关
void open_getline(bool f)
{
getline = f;
}
Qin &operator>>(ll &x)
{
x = read();
return *this;
}
Qin &operator>>(int &x)
{
x = read();
return *this;
}
Qin &operator>>(char &x)
{
x = getchar();
return *this;
}
Qin &operator>>(string &str)
{
rg char ch(1);
while (ch != '\0' && ch != '\n' && (ch != ' ' || getline))
{
ch = getchar();
str.push_back(ch);
}
return *this;
}
Qin &operator>>(char *str)
{
rg int i = 0;
rg char ch(1);
while (ch != '\0' && ch != '\n' && (ch != ' ' || getline))
{
ch = getchar();
str[i++] = ch;
}
return *this;
}
} qin;
class Qout
{
inline void write(int x)
{
static int sta[35];
rg int top(0);
do
{
sta[top++] = x % 10, x /= 10;
} while (x);
while (top)
putchar(sta[--top] + 48); // 48 是 '0'
}
public:
#define endl '\n'
inline Qout &operator<<(int x)
{
write(x);
return *this;
}
inline Qout &operator<<(char c)
{
putchar(c);
return *this;
}
inline Qout &operator<<(const string &str)
{
rg int len = str.length();
for (rg int i = 0; i < len; i++)
putchar(str[i]);
return *this;
}
inline Qout &operator<<(char *str)
{
rg int len = strlen(str);
for (rg int i = 0; i < len; i++)
putchar(str[i]);
return *this;
}
} qout;