C/C++ 通用代码模板


✅ C 语言代码模板(main.c

适用于基础项目、算法竞赛或刷题:

c 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

// 宏定义区
#define MAX_N 1000
#define INF 0x3f3f3f3f

// 函数声明
void solve();

int main() {
    // 快速读写(可选)
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    solve();
    return 0;
}

void solve() {
    // 示例:读取两个整数并输出和
    int a, b;
    printf("请输入两个整数:");
    scanf("%d %d", &a, &b);
    printf("它们的和是:%d\n", a + b);
}

✅ C++ 代码模板(main.cpp

适用于算法题、开发任务或初学者练习:

cpp 复制代码
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <limits>
#include <iomanip>

using namespace std;

// 宏定义(可选)
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int INF = 1e18;
const int MOD = 1e9 + 7;

// 函数声明
void solve();

int32_t main() {
    fastio;
    solve();
    return 0;
}

void solve() {
    // 示例:读取两个整数并输出它们的乘积
    int a, b;
    cout << "请输入两个整数:" << endl;
    cin >> a >> b;
    cout << "它们的乘积是:" << a * b << endl;
}
相关推荐
handler017 小时前
【Linux】信号:内核的“敲门声”
linux·运维·服务器·c++·c·信号·signal
fengkai45457 小时前
七、华为云网络类 + 计算类云服务实验总结
开发语言·php
T1mzhou7 小时前
ARM64 Linux 6.10内核启动流程6-psci.c和ATF/U-Boot 的电源接口
linux·服务器·c语言
神明不懂浪漫7 小时前
【第四章】索引——B+树、回表,加快数据库的查找能力的利器
开发语言·数据结构·数据库·经验分享·笔记·b树
博、、7 小时前
全民健身解决方案系统源码实战指南:从架构设计到部署全流程解析
开发语言·需求分析
liuze4087 小时前
安装boss-zhipin-mcp(招聘)
开发语言·python
是隼人7 小时前
buuctf-pwn PWN2(整数溢出)题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
博、、8 小时前
智慧场馆解决方案系统开发实战:从架构设计到落地指南
开发语言·需求分析
欧特克_Glodon8 小时前
OpenCV计算机视觉开发入门与实践<三十五>:开发视频播放器
c++·opencv·计算机视觉·音视频
二十雨辰8 小时前
[Java]-场景题
java·开发语言