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;
}
相关推荐
漂流瓶jz2 分钟前
UVA-11491 奖品的价值 题解答案代码 算法竞赛入门经典第二版
c++·算法·图论·题解·aoapc·算法竞赛入门经典·uva
weixin_307779134 小时前
C++代码实现MATLAB中的dlarray函数功能
开发语言·c++·算法·matlab
一水鉴天7 小时前
映射、哈希表与哈斯图:计算机科学的三种基线 20261003(元宝)
开发语言·人工智能
Frank_refuel7 小时前
C++11之一场名为“搬家”的 C++ 之旅
开发语言·c++
Wang's Blog8 小时前
Java 项目实战: 外卖平台优化-Nginx配置文件结构与块层级
java·开发语言·nginx
2601_962071579 小时前
类变量和全局变量的查找路径有什么区别?
开发语言·python
hetao17338379 小时前
2026-10-03~04 hetao1733837 的刷题记录
c++·算法
\光辉岁月/10 小时前
5.java-数组
java·开发语言
Java后端的Ai之路10 小时前
Python进阶探索29_eval内置函数
开发语言·python·探索·eval·内置函数
谢亮_vipxieliang10 小时前
Spring 事务失效的常见场景
java·开发语言·数据库·spring boot