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;
}
相关推荐
PAK向日葵2 小时前
我用 C++ 写了一个轻量级 Python 虚拟机,刚刚开源
c++·python·开源
玖釉-2 小时前
下一个排列:从字典序到原地算法的完整推导
数据结构·c++·windows·算法
枕星而眠2 小时前
数据结构八大排序详解(一):四大简单排序
c语言·数据结构·c++·后端
努力努力再努力wz3 小时前
【Qt入门系列】:按钮组件全解析:从 QAbstractButton 到快捷键事件、单选与复选机制
c语言·开发语言·数据结构·c++·git·qt·github
skywalk81633 小时前
言知(Yanzhi)系统提升建议报告和完工报告 by AutoCoder
开发语言·编程
yunn_4 小时前
单例模式两种实现方法
开发语言·c++·单例模式
我材不敲代码4 小时前
Python基础:列表详解、增删改查及常用高阶操作
开发语言·windows·python
AI玫瑰助手4 小时前
Python运算符:成员运算符(in/not in)的使用场景
开发语言·python·信息可视化
AI人工智能+电脑小能手4 小时前
【大白话说Java面试题 第77题】【Mysql篇】第7题:回表查询与全表扫描的区别?
java·开发语言·数据库·mysql·面试
水木流年追梦4 小时前
大模型入门-大模型分布式训练2
开发语言·分布式·python·算法·正则表达式·prompt