直接贴代码
//读入优化
inline int read()
{
char ch, c;
int res;
while (ch = getchar(), ch < '0' || ch > '9') c = ch;
res = ch - 48;
while (ch = getchar(), ch >= '0' && ch <= '9')
res = (res << 3) + (res << 1) + ch - 48;
if (c == '-') res = -res;
return res;
}
//输出优化
void write(int x)
{
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
然后在使用的时候
#include <cstdio>
int main()
{
int n;
n = read();
write(n);
}