核心

#define gc getchar()

template<class T>void rd(T&x){int f=1;x=0;char c=gc;while(c<48||c>57){if(c=='-')f=-1;c=gc;}while(47<c&&c<58)x=x*10+(c^48),c=gc;x*=f;}
template<class T>void wt(T x){if(x<0)putchar('-'),x=-x;if(x>9)wt(x/10);putchar(x%10+48);}

使用示例(A+B problem)

#include<cstdio>
#define gc getchar()
template<class T>void rd(T&x){int f=1;x=0;char c=gc;while(c<48||c>57){if(c=='-')f=-1;c=gc;}while(47<c&&c<58)x=x*10+(c^48),c=gc;x*=f;}
template<class T>void wt(T x){if(x<0)putchar('-'),x=-x;if(x>9)wt(x/10);putchar(x%10+48);}
int main(){
	int a,b;
    rd(a);
    rd(b);
    wt(a+b);
}