存个模板,以后直接copy懒得敲…… 不带负数:
int read_p,read_ca;inline int read(){ read_p=0;read_ca=getchar(); while(read_ca<'0'||read_ca>'9') read_ca=getchar(); while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar(); return read_p;}
带负数:
int read_p,read_ca,read_f;inline int read(){ read_p=0;read_ca=getchar();read_f=1; while(read_ca<'0'||read_ca>'9') { if (read_ca=='-') read_f=-1;read_ca=getchar();} while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar(); return read_p*read_f;}
区分出来是因为不带负数跑得稍微快一些……(稍微
用奇奇怪怪的变量名是为了不与主程序其他变量冲突。
输出优化(其实作用不大):
int pr_num,pr_ch[1000];inline void pr(long long k){ pr_num=0; while(k>0) pr_ch[++pr_num]=k%10,k/=10; while(pr_num) putchar(pr_ch[pr_num--]+48); putchar('\n');}