关于编程习惯问题

放个可靠的快读板子(注意cmath)

namespace IO
{
    const int __S=(1<<20)+5;char __buf[__S],*__H,*__T;
    inline char getc()
    {
        if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin);
        if(__H==__T) return -1;return *__H++;
    }
    template <class __I>inline void read(__I &__x)
    {
        __x=0;int __fg=1;char __c=getc();
        while(!isdigit(__c)&&__c!='-') __c=getc();
        if(__c=='-') __fg=-1,__c=getc();
        while(isdigit(__c)) __x=__x*10+__c-'0',__c=getc();
        __x*=__fg;
    }
    inline void readd(double &__x)
    {
        __x=0;double __fg=1.0;char __c=getc();
        while(!isdigit(__c)&&__c!='-') __c=getc();
        if(__c=='-') __fg=-1.0,__c=getc();
        while(isdigit(__c)) __x=__x*10.0+__c-'0',__c=getc();
        if(__c!='.'){__x=__x*__fg;return;}else while(!isdigit(__c)) __c=getc();
        double __t=1e-1;while(isdigit(__c)) __x=__x+1.0*(__c-'0')*__t,__t=__t*0.1,__c=getc();
        __x=__x*__fg;
    }
    inline void reads(char *__s,int __x)
    {
        char __c=getc();int __tot=__x-1;
        while(__c<'a'||__c>'z') __c=getc();
        while(__c>='a'&&__c<='z') __s[++__tot]=__c,__c=getc();
        __s[++__tot]='\0';
    }
    char __obuf[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr;
    inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;}
    inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();}
    template <class __I>inline void print(__I __x)
    {
        if(!__x) putc('0');
        if(__x<0) putc('-'),__x=-__x;
        while(__x) __qu[++__qr]=__x%10+'0',__x/=10;
        while(__qr) putc(__qu[__qr--]);
    }
    inline void prints(const char *__s,const int __x)
    {
        int __len=strlen(__s+__x);
        for(int __i=__x;__i<__len+__x;__i++) putc(__s[__i]);
    }
    inline void printd(long double __x,int __d)
    {
        long long __t=(long long)floor(__x);print(__t);putc('.');__x-=(double)__t;
        while(__d--)
        {
            long double __y=__x*10.0;__x*=10.0;
            int __c=(int)floor(__y+1e-9);if(__c==10) __c--;
            putc(__c+'0');__x-=floor(__y);
        }
    }
    inline void el(){putc('\n');}inline void sp(){putc(' ');}
}using namespace IO;

变量声明

声明能够使用简写,可是尽可能不要用太像的(好比$l$和$1$混用之类的)git

空间容许的状况下,必定要:数组

:%s/int/ll/g函数

遇到不能全开的状况必定要仔细检查,把每个在long long范围下的,以及和这些变量相关的变量都开成long longspa

循环问题

for循环的变量尽可能定义在外面code

auto仅可用在vector,set之类的地方字符串

while循环少用,注意跳出条件,以及循环内部跳出的位置get

尽可能不用gotoit

循环边界条件所有检查一遍!尤为是字符串题的字符集是10/26的时候,不要写了<9或者<25之类的玩意儿!for循环

定义数组的时候第二位的大小也要注意一下!!!!class

格式问题

一行最多用逗号链接两个语句一次,且这种状况下必须换行(也就是一行最多2个语句)

不一样的代码功能块之间要空行分块,必要时写注释

能传引用的尽可能不写返回值

注意不要大量往函数中传入数组之类的,若是必要请写引用

写法顺序

先从底层开始实现,若是有功能没法实现,能够先开一个函数放在那里,等会回来再写

注意这种时候必定要检查函数实现的功能是否正好是必要的功能

未完待续

相关文章
相关标签/搜索