手写快读

0
11
#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

  

<

发布回复

请输入评论!
请输入你的名字