跳到正文

闲话

我の代码风格

WizardCoderMinecraft约 8 分钟
原文

这是 2025年10月25日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月11日
收录
2025年12月12日
更新
2026年10月12日
篇幅
约 8 分钟

版本

  1. v2当前
  2. v1

我の代码风格

零: 前言

  • 问我为什么要写这个,当然是写给我自己看的
  • 更新:25/10/10 下面不会更新
原文件(.txt)
C++
										我的代码风格

										  零: 前言

	- 问我为什么要写这个,当然是写给我自己看的
	- 更新:25/10/10

										  一:框架

	Code:
		//训练不算什么!全靠毅力,实践需要毅力!
		#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define int ll
		#define endl "\n"
		const int N=1e6+5;
		const int INF=0x3f3f3f3f;
		const int MOD=1e9+7;
		const double PI=acos(-1);
		int n,m;
		int a[N];
		int p[N];
		
		int read(){
			int a=0,k=1;char c=getchar();
			while(!isdigit(c)){
				if(c=='-') k=-1;
				c=getchar();
			}
			while(isdigit(c)){
				a=a*10+c-'0';
				c=getchar();
			}
			return a*k;
		}
		
		int solve(){
			n=read();
			for(int i=1;i<=n;i++){
				cin>>a[i];
			}
			
			return 54188;
		}
		
		signed main(){
		//	freopen(".in","r",stdin);
		//	freopen(".out","w",stdout);
			int T=1;
			//cin>>T;
			while(T--){
				solve();
			}
			return 0;
		}
	
										二:快捷键

	- STL:
		a. pair
			#define st first
			#define nd second
			#define PII pair<int,int>
		b. 容器(e.g. vector、deque)
			#define puf push_front
			#define pub push_back
			#define pof pop_front
			#define pob pop_back

	- 生成
		a. 素数筛
			关键词:sushushai
			原型:
			void sushushai(int n){
				int i=0ll,j=0ll,m=(int)sqrt(n);
				for(i=2;i<=m;i++)
					if(!p[i])
						for(j=i*i;j<=n;j+=i) p[j]=1;
				for(i=2;i<=n;i++)
					if(!p[i]) printf("%lld ",i);
			}
		
		b. 方向数组(dfs/bfs的)
			关键词:Direction
			原型:
			//int dx[]={0,0,1,-1};
			//int dy[]={1,-1,0,0};
			//int dx[]={-1,1,0,0,-1,1,-1,1};
			//int dy[]={0,0,-1,1,-1,1,1,-1};
			//int dl[]={1,-1,0,0,0,0};
			//int dx[]={0,0,1,-1,0,0};
			//int dy[]={0,0,0,0,1,-1};

		c. 分割线(没啥用)
			关键词:fengexian
			原型:
			//------------------------------------------------------------
		
		d. 文件IO
			关键词:file
			原型:
			freopen(".in","r",stdin);
			freopen(".out","w",stdout);
			
三:返回值
	- solve返回值:
		-> 正常结束:54188
		-> 特判结束:-1
		-> 调试:(n)  (n是阶段,如1,2,3...)
		-> 强制:-2

一:框架

CodeCode
C++
//训练不算什么!全靠毅力,实践需要毅力!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define endl "\n"
const int N=1e6+5;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const double PI=acos(-1);
int n,m;
int a[N];
int p[N];

int read(){
  int a=0,k=1;char c=getchar();
  while(!isdigit(c)){
    if(c=='-') k=-1;
    c=getchar();
  }
  while(isdigit(c)){
    a=a*10+c-'0';
    c=getchar();
  }
  return a*k;
}

int solve(){
  n=read();
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  
  return 54188;
}

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
  int T=1;
  //cin>>T;
  while(T--){
    solve();
  }
  return 0;
}

二:快捷键

STL:

a. pair
CodeCode
代码
#define st first
#define nd second
#define PII pair<int,int>
b. 容器(e.g. vector、deque)
CodeCode
代码
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back

生成

a. 素数筛
  • 关键词:sushushai
  • 原型:
CodeCode
C++
void sushushai(int n){
  int i=0ll,j=0ll,m=(int)sqrt(n);
  for(i=2;i<=m;i++)
    if(!p[i])
      for(j=i*i;j<=n;j+=i) p[j]=1;
  for(i=2;i<=n;i++)
    if(!p[i]) printf("%lld ",i);
}
b. 方向数组(dfs/bfs的)
  • 关键词:Direction
  • 原型:
CodeCode
C++
//int dx[]={0,0,1,-1};
//int dy[]={1,-1,0,0};
//int dx[]={-1,1,0,0,-1,1,-1,1};
//int dy[]={0,0,-1,1,-1,1,1,-1};
//int dl[]={1,-1,0,0,0,0};
//int dx[]={0,0,1,-1,0,0};
//int dy[]={0,0,0,0,1,-1};
c. 分割线(没啥用)
  • 关键词:fengexian
  • 原型:
CodeCode
代码
			//------------------------------------------------------------
d. 文件IO
  • 关键词:file
  • 原型:
CodeCode
代码
freopen(".in","r",stdin);
freopen(".out","w",stdout);

三:返回值

solve()返回值:(不建议学)

  1. 正常结束:“Successfully return”
  2. 特判结束:“Special return”
  3. 调试:n(n是阶段,如1,2,3…)

main()返回值:

只有0(别问为什么)