快读/快输 · 模版

本文介绍了C++中实现快速输入输出的模版方法,包括快读快输的技巧,适用于处理大量数据时提高程序效率。详细讲解了针对不同数据类型的快读(long long)等,并提供了将普通输入输出转化为快速输入输出的建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

快读一

inline int read(){
   
    int f=1,x=0;char c=getchar();
    while(!isdigit(c)){
   if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)){
   x=(x<<3)+(x<<1)+(c^48);c=getchar();}
    x *= f; return x;
}

快读二

typedef long long LL;
#define gc pa==pb&&(pb=(pa=buf)+fread(buf,1,100000,stdin),pa==pb)?EOF:*pa++
static char buf[100000],*pa(buf),*pb(buf);
inline LL readint() {
   
    LL x=0;char c=gc;
    while(c<'0'||c>'9')c=gc;
    for(;c>='0'&&c<='9';c=gc)x=x*10+(c&15);
    return x;
}

快读三

template<class T>inline
void read(T &x)
{
   
        x = 0; int f = 1; char c = getchar();
        while (!isdigit(c)){
   if (c == '-') f = -1; c = getchar();}
        while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
        x *= f; 
} 

快读(long long)

ll read(){
   
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
   if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){
   x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

快输

inline void print(int x){
   
    if(x<0){
   putchar('-');x=-x;}
    if(x>9)print(x/10);
    putchar(x%10+48);
}

直接把 cincoutendl 改成快速

#include <fstream>
#include <iostream>

namespace Fast_I {
   
char *_Buf, *_Start_ptr, *_End_ptr;
std::streambuf* inbuf;
unsigned int Size;
bool _Ok;

struct Fast_Istream {
   
  operator bool() {
    return _Ok; }
  Fast_Istream(std::streambuf*, unsigned int);
  Fast_Istream(unsigned int);
  Fast_Istream(const char*, unsigned int);
  Fast_Istream& operator>>(char&);
  Fast_Istream& operator>>(char*);
  Fast_Istream& operator>>(bool&);
  Fast_Istream& operator>>(short&);
  Fast_Istream& operator>>(int&);
  Fast_Istream& operator>>(long&);
  Fast_Istream& operator>>(long long&);
  Fast_Istream& operator>>(unsigned short&);
  Fast_Istream& operator>>(unsigned int&);
  Fast_Istream& operator>>(unsigned long&);
  Fast_Istream& operator>>(unsigned long long&);
  Fast_Istream& operator>>(float&);
  Fast_Istream& operator>>(double&);
  Fast_Istream& operator>>(long double&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值