讀寫
__int128
ostream& operator<<(ostream& output, lnt integer)
{
if (integer < 0)
{
output << '-'; integer *= -1;
}
string str;
do
{
str.push_back('0' + char(integer % 10)); integer /= 10;
} while (integer != 0);
reverse(str.begin(), str.end());
output << str;
return output;
}
istream& operator>>(istream& input, lnt& integer)
{
string str; input >> str; integer = 0;
for (int i = 0; i < str.size(); ++i)
{
integer = integer * 10 + str[i] - '0';
}
return input;
}
快讀快寫
namespace FastIO
{
template<int SIZE>
class C_IOBUF
{
private:
char p[SIZE], * p1, * p2, q[SIZE], * q1, * q2;
public:
C_IOBUF(void) { p1 = p2 = p, q1 = q, q2 = q + SIZE; }
char GetChar(void)
{
return p1 == p2 && (p2 = (p1 = p) + fread(p, 1, SIZE, stdin)), p1 == p2 ? EOF : *p1++;
}
void PutChar(char c)
{
if (q1 == q2) q2 = (q1 = q) + fwrite(q, 1, SIZE, stdout); *q1++ = c;
}
~C_IOBUF(void) { fwrite(q, 1, q1 - q, stdout); }
};
C_IOBUF<1 << 20>BUF;
class C_IStream
{
private:
bool IsChar(const char& c)
{
return c != ' ' && c != '\n';
}
bool IsDigit(const char& c)
{
return '0' <= c && c <= '9';
}
public:
C_IStream& operator >>(int& temp)
{
temp = 0; char c = BUF.GetChar(); bool flag = false;
while (IsDigit(c) != true) { if (c == '-')flag = true; c = BUF.GetChar(); }
while (IsDigit(c) == true) { temp = temp * 10 + c - '0', c = BUF.GetChar(); }
temp = flag ? -temp : temp; return *this;
}
C_IStream& operator >>(lnt& temp)
{
temp = 0; char c = BUF.GetChar(); bool flag = false;
while (IsDigit(c) != true) { if (c == '-')flag = true; c = BUF.GetChar(); }
while (IsDigit(c) == true) { temp = temp * 10 + c - '0', c = BUF.GetChar(); }
temp = flag ? -temp : temp; return *this;
}
C_IStream& operator >>(char& temp)
{
temp = ' '; char c = BUF.GetChar();
while (IsChar(c) != true)c = BUF.GetChar();
temp = c; return *this;
}
C_IStream& operator >>(string& temp)
{
temp.clear(); char c = BUF.GetChar();
while (IsChar(c) != true)c = BUF.GetChar();
while (IsChar(c) == true)temp += c, c = BUF.GetChar();
return *this;
}
}cin;
class C_OStream
{
public:
C_OStream& operator <<(int temp)
{
int Top = 0; static int Stack[64];
if (temp < 0) { BUF.PutChar('-'); temp = -temp; }
do { Stack[Top++] = temp % 10; temp /= 10; } while (temp);
while (Top) { BUF.PutChar(Stack[--Top] + '0'); } return *this;
}
C_OStream& operator <<(lnt temp)
{
int Top = 0; static int Stack[64];
if (temp < 0) { BUF.PutChar('-'); temp = -temp; }
do { Stack[Top++] = temp % 10; temp /= 10; } while (temp);
while (Top) { BUF.PutChar(Stack[--Top] + '0'); } return *this;
}
C_OStream& operator <<(char temp)
{
BUF.PutChar(temp); return *this;
}
C_OStream& operator <<(string temp)
{
for (auto c : temp)BUF.PutChar(c); return *this;
}
C_OStream& operator <<(const char temp[])
{
int p = 0; while (temp[p] != '\0')BUF.PutChar(temp[p++]); return *this;
}
}cout;
}