\[\text{Duyi-4th-Code-Standard}\]
- 四格缩进。
- 通常情况下下标从1开始,多项式等特殊的地方视情况而定。
for
循环不简写为rep(i,1,n)
,循环变量不定义成register
型。- 大括号不换行,不空格,运算符也不空格。没有大括号时不可以换行+缩进(要么压到同一行,要么加上大括号)
- 一些STL中函数名会利用宏来简化(如
#define pb push_back
)。 - 常规的、套路的、工具性的数据结构尽可能打包在结构体中,即使全文只有一个这样的数据结构。
- 非常短的语句要压行,很套路的语句可以压成一行(如链式前向星的
add_edge
函数,快速幂的pow_mod
函数)。 - 常量名全部大写(如
const int INF=1e9
);由多个单词组成的函数名和变量名采用小写,单词之间用下划线分隔(如add_edge
);类(和结构体)名中每个单词首字母大写,不使用下划线(如SegmentTree
)。 - 读入文件全是数字时使用读入优化
read()
,否则用cin/scanf
。严格禁止read()
和cin/scanf
混用。
修正案:
upd 2019.10.26 如果for
循环的层数大于6,for
循环可以简写为rep
。
upd 2020.1.6 原则上提倡区间左闭右闭。涉及数组下标的比较、边界判定,应尽量使用<=
,>=
代替<
和>
。
upd 2020.1.6 在用宏定义的方式保证了在本地运行时标准输入能正常使用(不需要ctrl+Z
)的前提下,可以使用fread
。具体见下面的缺省源。
upd 2020.2.8 “二分答案”的写法不在2020.1.6提出的“左闭右闭原则”的讨论范围之内,属于历史遗留问题,特此说明。
upd 2020.2.27 namespace
里的内容应和namespace
外的内容在缩进上齐平。namespace
结束的地方的}
处建议加上注释//namespace XXXX
,以此避免上下两个连续的大括号造成的不好的视觉效果。具体见下面的缺省源。
以下是根据duyi第四代代码标准设计出的缺省源(C++版本
)。它具有简单便捷灵活高效美观的特点,可以广泛应用在各种算法竞赛和工程代码中。
//problem:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
namespace Fread{
const int MAXN=1<<20;
char buf[MAXN],*S,*T;
inline char getchar(){
if(S==T){
T=(S=buf)+fread(buf,1,MAXN,stdin);
if(S==T)return EOF;
}
return *S++;
}
}//namespace Fread
#ifdef ONLINE_JUDGE
#define getchar Fread::getchar
#endif
inline int read(){
int f=1,x=0;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline ll readll(){
ll f=1,x=0;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
/* ------ by:duyi ------ */ // dysyn1314
int main() {
return 0;
}