读优 输优

Code:

标风:

#include
#include

inline void read(int &f) {
    f = 0; int flag = 1; char c = getchar();
    while (!isdigit(c)) { if (c == '-') flag = -1; c =getchar();}
    while (isdigit(c)) f = (f<<1) + (f<<3) + c - 48, c = getchar();
}

void write(int x) {
    if (x > 9) write(x / 10); putchar(x % 10 + 48); return;
}

void write_(int x) {
    if (x < 0) putchar('-'), x = -x;
    write(x); putchar(' ');
}

void writeln(int x) {
    if (x < 0) putchar('-'), x = -x;
    write(x); putchar('\n');
}

注释版:

#include
#include
#include
using namespace std;
inline void read(int &f) {
//地址符,也就是说如果read(n),n的值会随着f的值变换而变换
	f=0;int flag=1; char c=getchar();
	//flag判断正负
	while(!isdigit(c)) {if (c=='-') flag=-1; c=getchar();}
	while(isdigit(c)) {f=(f<<3)+(f<<1)+c-48; c=getchar();}
	//isdigit(c)用来判断(int)c是否在范围48~57之间,是则return 1 else return 0
	f*=flag; return;
}
void write(int x) {
	if(x>9) write(x/10);putchar(x%10+48);return;
}
void write_(int x) {
	if(x<0)putchar('-'),x=-x;//判断负数
	write(x); putchar(' '); return;
}
void writeln(int x) {
	if(x<0)putchar('-'),x=-x;//判断负数
	write(x); putchar('\n'); return;
}
int main() {
	int x;read(x);
	write_(x); writeln(x);
	write_(x); write(x)
}

无注释版

#include
#include
#include
using namespace std;
inline void read(int &f) {
	f=0;int flag=1; char c=getchar();
	while(!isdigit(c)) {if (c=='-') flag=-1; c=getchar();}
	while(isdigit(c)) {f=(f<<3)+(f<<1)+c-48; c=getchar();}
	f*=flag; return;
}
void write(int x) {
	if(x>9) write(x/10);putchar(x%10+48);return;
}
void write_(int x) {
	if(x<0)putchar('-'),x=-x;
	write(x); putchar(' '); return;
}
void writeln(int x) {
	if(x<0)putchar('-'),x=-x;
	write(x); putchar('\n'); return;
}
int main() {
	int x;read(x);
	write_(x); writeln(x);
	write_(x); write(x)
}

fread & fwrite版:

#include
#include

using namespace std;

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ?EOF : *p1++)
char buf[1<<21], *p1 = buf, *p2 = buf, buff[1<<21], a[20];
int p_, p__ = -1;

inline void read(int &f) {
    f = 0; int flag = 1; char c = getchar();
    while (!isdigit(c)) { if (c == '-') flag = -1; c =getchar();}
    while (isdigit(c)) f = (f<<1) + (f<<3) + c - 48, c = getchar();
}

inline void flush() {
    fwrite(buff, 1, p__+1, stdout), p__ = -1;
}

inline void write(int x) {
    if (p__ > (1 << 20)) flush();
    if (x < 0) buff[++p__] = 45, x = -x;
    do {
        a[++p_] = x % 10 + 48;
    } while(x/=10);
    do {
        buff[++p__] = a[p_];
    } while(--p_);
}

inline void writeln(int x) {
	write(x);
    buff[++p__] = '\n';
}

int main() {
	freopen("1.txt", "r", stdin);
	freopen("2.txt", "w", stdout);
	int n;
	read(n);
	writeln(n);
	write(n);
	if (p__ != -1) flush();
}


你可能感兴趣的:(其他)