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;
}
相关推荐
熊猫钓鱼>_>4 分钟前
大学图论第 6 讲:网络流与二分图匹配——对偶性让瓶颈自己现形
开发语言·算法·面试·职场和发展·图论·校招·面经
方便面不加香菜5 分钟前
C++ 关于多态的知识点讲解
开发语言·c++
jimy125 分钟前
C++ 类成员函数的内联定义(inline)详解
开发语言·c++
Nebula_g31 分钟前
JavaSE高级:动态代理
java·开发语言·算法·javase
sanqima1 小时前
CreateThread、_beginthreadex、AfxBeginThread三种线程创建的区别与联系
c++·tls·线程创建
青春逝如流水1 小时前
Java 线程与操作系统、硬件的关系:状态、映射与差异
java·开发语言·多线程·ai文章
sanqima1 小时前
依赖TLS和模块状态的MFC类
c++·mfc·tls·module state
谢亮_vipxieliang1 小时前
Go gRPC基础与实战
开发语言·后端·golang
All for pursuit.1 小时前
【动态规划-11】279.完全平方数
数据结构·c++·算法·leetcode·动态规划
Aurorar0rua1 小时前
CS50 x 2024 Notes Data structures - 08
c语言·开发语言·学习方法