手写快读
程序员文章站
2022-04-15 23:27:10
#ifndef _GLIBCXX_read #define _GLIBCXX_read 1 #progma GCC system_header #include namespace std _GLIBCXX_VISIBILITY(default){ _GLIBCXX_BEGIN_N ......
#ifndef _glibcxx_read
#define _glibcxx_read 1
#progma gcc system_header
#include <cstdio>
namespace std _glibcxx_visibility(default){
_glibcxx_begin_namespace_version
void pushint(int &index,int pushindex){
index*=10;
index+=pushindex;
}
template<typename intype>
intype readint(){
char c;
bool fs=false;
c=getchar();
intype finally=0;
if(c=='-'){
fs=true;
}
else{
if(c<'0'||c>'9'){
return finally;
}
else{
push(finally,c-'0');
}
}
while(1){
c=getchar();
if(c<'0'||c>'9'){
break;
}
else{
push(finally,c-'0');
}
}
return (fs?(0-finally):finally);
}
#define readchar getchar()
_glibcxx_end_namespace_version
}
#endif
将以上代码保存为read.h,使用时只需#include "read.h"即可(注意:一定要在相同目录下!!!)
支持读入整数int x=readint<int>(); or long long x=readint<long long>(); or long x=readint<long>(); or short x=readint<short>();
如果要提交题目怎么办??
答:取出你要用的部分即可。
读入整数:
void pushint(int &index,int pushindex){
index*=10;
index+=pushindex;
}
template<typename intype>
intype readint(){
char c;
bool fs=false;
c=getchar();
intype finally=0;
if(c=='-'){
fs=true;
}
else{
if(c<'0'||c>'9'){
return finally;
}
else{
push(finally,c-'0');
}
}
while(1){
c=getchar();
if(c<'0'||c>'9'){
break;
}
else{
push(finally,c-'0');
}
}
return (fs?(0-finally):finally);
}
读入字符:
#define readchar getchar
上一篇: Flow 静态类型检查开发环境搭建
下一篇: 彻底搞懂Python一切皆对象,面试必过