代码风格
  • 板块灌水区
  • 楼主Ace_Maochang
  • 当前回复30
  • 已保存回复30
  • 发布时间2023/9/9 11:42
  • 上次更新2023/11/2 22:10:48
查看原帖
代码风格
707144
Ace_Maochang楼主2023/9/9 11:42

同学们总是吐槽我的代码风格,有没有大佬指导一下我的代码风格上有没有可以改进的地方

以下是例子:

#include<bits/stdc++.h>
using namespace std;
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int t,cnt,r1,c1,r2,c2,n,m;
bool s[101][101];
void dfs(int t,int x,int y){
	if(x==r2&&y==c2&&t==0){
		cnt++;
	}
	 if(!t||abs(x-r2)+abs(y-c2)>t)return;
	for(int i=0;i<4;i++){
		int xx=x+dx[i];
		int yy=y+dy[i];
		if(xx>=1&&yy>=1&&xx<=n&&yy<=m&&(s[xx][yy])){
			dfs(t-1,xx,yy);
		}
	}
}
char temp;

int main(){
	cin>>n>>m>>t;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>temp;
			if(temp=='.')	s[i][j]=true;
			else s[i][j]=false;
		}
	}
	cin>>r1>>c1>>r2>>c2;
	dfs(t,r1,c1);
	cout<<cnt;
	return 0;
}

2023/9/9 11:42
加载中...