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;
}
相关推荐
Alex艾力的IT数字空间16 分钟前
完整事务性能瓶颈分析案例:支付系统事务雪崩优化
开发语言·数据结构·数据库·分布式·算法·中间件·php
玖剹23 分钟前
二叉树递归题目(一)
c语言·c++·算法·leetcode
mjhcsp27 分钟前
C++ 数组:基础与进阶全解析
开发语言·c++
量子炒饭大师29 分钟前
【一天一个计算机知识】—— 【编程百度】翻译环境与运行环境
c语言·汇编·c++·gitee·机器翻译
5335ld35 分钟前
后端给的post 方法但是要求传表单数据格式(没有{})
开发语言·前端·javascript·vue.js·ecmascript
量子炒饭大师40 分钟前
【一天一个计算机知识】—— 【编程百度】预处理指令
java·开发语言
任子菲阳1 小时前
学Java第四十四天——Map实现类的源码解析
java·开发语言
听风吟丶1 小时前
Java 11+ HttpClient 实战:从 HttpURLConnection 到现代 HTTP 客户端的全面升级
java·开发语言·http
今晚打老虎1 小时前
c++(斗罗大陆3)
开发语言·c++·斗罗大陆3
mywpython1 小时前
Python使用消息队列rabbitmq
开发语言·python·rabbitmq