zoukankan      html  css  js  c++  java
  • 手写快读

    #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
    

      

  • 相关阅读:
    .NET XmlNavigator with Namespace
    编程要素
    【FOJ】1962 新击鼓传花游戏
    【POJ】1389 Area of Simple Polygons
    【POJ】2482 Stars in Your Window
    【HDU】3265 Posters
    【HDU】1199 Color the Ball
    【HDU】3642 Get The Treasury
    【HDU】4027 Can you answer these queries?
    【HDU】1542 Atlantis
  • 原文地址:https://www.cnblogs.com/eason66-blog/p/read.html
Copyright © 2011-2022 走看看