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;
}
相关推荐
Blossom.1184 分钟前
使用Python和TensorFlow实现图像分类的人工智能应用
开发语言·人工智能·python·深度学习·安全·机器学习·tensorflow
CodeWithMe29 分钟前
【C/C++】C++中noexcept的妙用与性能提升
c语言·开发语言·c++
非著名架构师30 分钟前
C++跨平台开发实践:深入解析与常见问题处理指南
开发语言·c++
SuperCandyXu35 分钟前
leetcode0310. 最小高度树-medium
数据结构·c++·算法·leetcode
越来越无动于衷35 分钟前
JAVA多态——向上转型
java·开发语言
鱼嘻1 小时前
线程邮箱框架与示例
linux·c语言·开发语言·算法·php
jz_ddk1 小时前
[学习]RTKLib详解:ephemeris.c与rinex.c
c语言·网络·学习
虾球xz1 小时前
游戏引擎学习第264天:将按钮添加到分析器
c++·学习·游戏引擎
cooldream20091 小时前
有状态服务、无状态服务与Session机制详解
java·开发语言·系统架构师
YKPG1 小时前
C++学习-入门到精通-【5】类模板array和vector、异常捕获
java·c++·学习