讀優 輸優

Code:

標風:

#include<cstdio>
#include<iostream>

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<cstdio>
#include<iostream>
#include<algorithm>
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<cstdio>
#include<iostream>
#include<algorithm>
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<cstdio>
#include<iostream>

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();
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章