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;
}
相关推荐
FLJwu11 小时前
运动相机采购选型避坑实战|第二篇
c语言·开发语言·数码相机·运动相机·oem 量产
诚丞成11 小时前
Kavita真正好用的不是“远程阅读”:而是把NAS目录重新组织成可扫描的Library
开发语言·网络
Kimi-学长11 小时前
PHP 爆出两个高危安全漏洞!CVE-2026-109618、CVE-2026-109619 修复方案与防护指南
开发语言·php
程序猿编码12 小时前
不用 PyTorch!从零手写 C++ 深度学习框架,自动微分、CUDA、分布式一把搞定
c++·深度学习·大模型推理·自动微分
real_metrix12 小时前
【学习笔记】C/C++ 头文件自包含
c++·c·头文件·自包含
“AI国潮设计-小江”12 小时前
《【AIGC实战】Python+SDXL批量生成“英歌舞草莓抱抱卷蛋糕”IP插牌立牌方案,锁定角色一致性,甜品插件化落地》
开发语言·人工智能·python·prompt·aigc
雪落漂泊12 小时前
C++算法 滑动窗口篇(上)
开发语言·c++·算法
像枫一样12 小时前
STM32串口轮询收发实战教程
arm开发·c++·stm32·单片机·嵌入式硬件·fpga开发·51单片机
估值探索者12 小时前
【Python量化技术指标实战 04】布林带通道突破,怎么知道是真突破还是假突破?
java·开发语言·python·接口·股票数据api接口
Soneswy12 小时前
C++基础篇——类与对象(上)
开发语言·c++