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;
}
相关推荐
lhldsg11 小时前
全民健身解决方案:从共享球场到智能运营的技术实践
java·大数据·开发语言·需求分析
归去来?11 小时前
Python 常用优雅写法
开发语言·python
Yyyyyy~11 小时前
【C语言】数据类型和变量【下】
c语言
devilnumber11 小时前
Java 30 组高频技术 / 知识点多角度对比
java·开发语言
何以解忧,唯有..12 小时前
Python 异常处理完全指南:从基础到高级实践
开发语言·前端·python
啦啦啦啦啦zzzz12 小时前
时间轮定时器
linux·服务器·网络·c++·定时器
gugucoding12 小时前
57. 【Java】日志框架:SLF4J与Logback
java·开发语言·logback
此生决int12 小时前
深入理解C++系列(15)——AVL树
开发语言·c++
一只旭宝12 小时前
预约系统版本2(pyhton+flask可视化版本)
服务器·数据库·c++·笔记·python·flask
筱璦12 小时前
PHP+ VUE3机构级股票分仓管理交易系统源码可出
开发语言·php·vue3·量化·股票分仓