I/O 优化

数字的读入优化:

/* I/O
 * Au: GG
 */

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <stack>
using namespace std;

int read() {
	int sum = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c))
		sum = sum * 10 + c - '0', c = getchar();
	return sum;
}
void write(int num) {
	if (!num) putchar('0');
	else {
		stack<int> st;
		while (num > 0)
			st.push((char) (num % 10 + '0')),
			num /= 10;
		while (!st.empty())
			putchar((char) (st.top())),
			st.pop();
	}
}
void writeln(int num) {write(num); putchar('
');}

int main() {
	for (int i = 1; i <= 5; i++) {
		int j = read();
		writeln(j);
	}
	return 0;
}

Post author 作者: Grey
Copyright Notice 版权说明: Except where otherwise noted, all content of this blog is licensed under a CC BY-NC-SA 4.0 International license. 除非另有说明,本博客上的所有文章均受 知识共享署名 - 非商业性使用 - 相同方式共享 4.0 国际许可协议 保护。
原文地址:https://www.cnblogs.com/greyqz/p/7560201.html