ghj1222的代码规范

基本上和notepad++的要求一样。

不定期更新。

1.左大括号换行:

int main()
{
    
    return 0;
}

可能有些同志(比如大佬cjh)和我的做法不一样

当一个函数很短的时候可以整个函数写一行:

Vector operator+(const Vector &a, const Vector &b) { return Vector(a.x + a.y, b.x + b.y); }

一定要保证两个匹配的括号在同一行或同一列

2.双目运算符连接的操作数之间要有空格、单目运算符与操作数之间不空格。

int main()
{
    cout << a + b << endl;
    return 0;
}

3.不在行末的分号、逗号后面接一个空格,前面紧贴。

int main()
{
    int n = 5;
    for (int i = 1; i <= n; i++)
    {
        int tmp1 = 1, tmp2 = 2;
        tmp1 = 3, tmp2 = 4;
    }
}

4.可以使用using namespace std;#include <bits/stdc++.h>

部分旧版编译器不支持bits/stdc++.h,只需要更新编译器而不是更改代码

由于我目前使用的编译器不用万能头秒出exe,用的话要等1s,所以现在不用万能头但是不反对万能头

5.对变量名命名不做要求,但是应该取能简单的表达变量代表意义的英文名,避免使用中文全拼。

倾向于使用简写(但是能看懂原意:例如cnt,pos,ans,res等)

Good:bucket,pos

Bad:tong,weizhi

慎用英语老师教给你的英文单词,可能和标准库冲突。

6.倾向于使用i++而非++i(个人习惯,现代编译器他俩是一样的)

7.流程控制关键字后面加空格,函数名等后面不加空格

例如:

#include <bits/stdc++.h>
using namespace std;
int a[100010];

int main()
{
    for (int i = 1; i <= 100; i++)
        scanf("%d", &a[i]);
    sort(a + 1, a + 101);
    return 0;
}
posted @ 2018-11-29 19:45  ghj1222  阅读(347)  评论(0编辑  收藏  举报