前言 - 简介
我们在写代码的过程中, 不可避免的重度依赖所处的开发环境. 本文重点带大家在 Window 搭建 C
简单控制台项目. 当作存档, 用于记录项目搭建各种重复操作. 在详细过程之前, 我们约定下基础环境
Best new version Window
Best new version Visual Studio
例如笔者当前是 Windows 10 + Visual Studio 2019, 其中 Windows 推荐开启 UTF-8 支持.
那此间, 骚年去唤醒自己的道 ~
正文 - 过程
正文分三个过程. 其一是 Visual Studio C Consule 常用设置. 其二是导出模板, 来解放生产力. 其三演示使用.
Visual Studio C Consule 常用设置
1. 创建 c_template 项目
2. 只保留 x64 环境
人的精气有限, 做钉子更省力.
3. 添加基础 main.c
4. Visual Studio 项目详细配置
导出模板
上面这些每次操作都添加, 很恶心. 我们可以通过 [项目] -> [导出模板] 一劳永逸. ~
1. 前戏
找到 c_template.vcxproj 项目文件, 通过你的慧眼, 将其中所有关于 Win32 相关的 xml 配置删除.
2. 导出模板
[项目] -> [导出模板]
添加额外补充
(图片什么的可以因自己喜好自己整)
演示使用
最终生成如下模板内容
不妨既兴通过这个模板演示一段代码
#include <stdio.h>
#include <float.h>
#include <errno.h>
#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h> /*
题目:
地上右一个 m 行 n 列的方格.
一个机器人从坐标(0, 0) 的格子开始移动, 它每次可以向左, 右, 上, 下移动一格,
但不能进入行坐标和列坐标的数位之和大于 k 的格子. 例如, 当 k 为 18 的时候,
机器人能够进入方格 (35, 37), 因为 3 + 5 + 3 + 7 = 18.
但它不能进入方格 (35, 38), 因为 3 + 5 + 3 + 9 = 19.
请问该机器人能够到达多少个格子?
*/ extern int moving_count(int m, int n, int threshold); int main(int argc, char * argv[]) {
int m = , n = , threshold = ;
int count = moving_count(m, n, threshold);
printf("<m = %d, n = %d, threshold = %d> -> %d\n", m, n, threshold, count);
return ;
} struct visite {
int rows;
int cols;
int threshold;
bool visited[];
}; inline struct visite * visite_create(int rows, int cols, int threshold) {
struct visite * v = malloc(sizeof(struct visite) + (rows * cols) * sizeof (int));
assert(v && rows > && cols > && threshold > );
v->rows = rows;
v->cols = cols;
v->threshold = threshold;
memset(v->visited, , (rows * cols) * sizeof (int));
return v;
} inline void visite_delete(struct visite * v) {
if (v) free(v);
} static inline int get_digit_sum(int num) {
int sum = ;
while (num > ) {
sum = num % ;
num /= ;
}
return sum;
} inline bool visite_check(struct visite * v, int row, int col) {
if (row >= && row < v->rows && col >= && col < v->cols && !v->visited[row * v->cols + col]) {
return get_digit_sum(row) + get_digit_sum(col) <= v->threshold;
}
return false;
} int visite_moving(struct visite * v, int row, int col) {
if (!visite_check(v, row, col))
return ; v->visited[row * v->cols + col] = true;
return + visite_moving(v, row, col - )
+ visite_moving(v, row, col + )
+ visite_moving(v, row - , col)
+ visite_moving(v, row + , col);
} int
moving_count(int m, int n, int threshold) {
if (m < || n < || threshold < )
return ;
if (threshold == )
return ; struct visite * v = visite_create(m, n, threshold); int count = visite_moving(v, , ); visite_delete(v); return count;
}
(有心的道友, 也可以转成栈回溯. )
后记 - 展望
错误是难免的, 欢迎朋友指正互相印证苦中作乐.
立秋 - 刘翰 - 南宋
乳鸦啼散玉屏空,一枕新凉一扇风。
睡起秋声无觅处,满阶梧桐月明中。