zoukankan      html  css  js  c++  java
  • 关于编程习惯问题

    放个可靠的快读板子(注意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]='';
        }
        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('
    ');}inline void sp(){putc(' ');}
    }using namespace IO;
    
    

    变量声明

    声明可以使用简写,但是尽量不要用太像的(比如$l$和$1$混用之类的)

    空间允许的情况下,一定要:

    :%s/int/ll/g

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

    循环问题

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

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

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

    尽量不用goto

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

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

    格式问题

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

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

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

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

    写法顺序

    先从底层开始实现,如果有功能无法实现,可以先开一个函数放在那里,等会回来再写

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

    未完待续

  • 相关阅读:
    etl接口测试总结
    LR controller 参数化
    Mysql导入导出命令
    mysql基本命令
    mysql用户管理(新增用户及权限管理)
    源码编译搭建LAMP
    【OpenGL】Shader实例分析(一)-Wave
    仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)
    cocos2d-x游戏开发(十四)用shader使图片背景透明
    泰然发布了一系列 OpenGL3.0 的教程,推荐大家参考学习
  • 原文地址:https://www.cnblogs.com/dedicatus545/p/9742926.html
Copyright © 2011-2022 走看看