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;
}
相关推荐
罗超驿7 分钟前
6.Java LinkedList深度解析:从链表原理到源码实践
java·开发语言·链表
2501_9481069110 分钟前
计算机毕业设计之jsp物业管理系统
java·大数据·开发语言·汽车·课程设计
逝水无殇20 分钟前
C# 反射详解
开发语言·后端·c#
阿米亚波33 分钟前
【C++ STL】std::list
c++·windows·笔记·stl·list
橙色阳光五月天35 分钟前
CMake 构建配置文件解析
c++·cmake·plugin
xlxxy_36 分钟前
sap获取批次特性报表
java·linux·开发语言·前端·数据库·abap·mm
北冥you鱼37 分钟前
Go语言常用包使用指南:从标准库到第三方利器
开发语言·microsoft·golang
俺不中嘞1 小时前
python常用函数
开发语言·python
欢喜躲在眉梢里1 小时前
用飞算Java做了一套新能源充电运营管理系统:把站点、设备、订单拆成可运营的微服务
java·开发语言·微服务·ai编程·技术分享·java开发·飞算javaai炫技赛
载数而行5201 小时前
C++进阶 Linux相关的静态库,动态库,第三方库
c++