跳到正文

休闲·娱乐

"太简单了"(I)

sunyongkang123约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年8月25日
收录
2026年9月13日
更新
2026年11月14日
篇幅
约 3 分钟

版本

  1. v1当前

众众众所统治A+B Problem很简单 就是:

C++
#include<iostream>
using namespace std;
int main(){
    int a,b;cin >> a >> b;
    cout << a+b <<endl;
    return 0;
}

应该是个入学过OI就会吧 但这样未免太简单了

咱们就可以将int改为long long

就是:

C++
#include<iostream>
using namespace std;
int main(){
    long long a,b;cin >> a >> b;
    cout << a+b <<endl;
    return 0;
}

但是这样太不整洁了

都学过函数吧,可以用函数来整洁一下

就是:

C++
#include<iostream>
using namespace std;
void init(long long a,long long b){
    cin >> a >> b;
    cout << a+b <<endl;
}
int main(){
    long long a,b;
    init(a,b);
    return 0;
}

你们没发现每次写一个long long太麻烦了 就可以用一个宏定义

belike:

C++
#include<iostream>
typedef long long ll;
using namespace std;
void init(ll a,ll b){
    cin >> a >> b;
    cout << a+b <<endl;
}
int main(){
    ll a,b;
    init(a,b);
    return 0;
}

咱们先加个ios快读 也就是:

C++
#include<iostream>
typedef long long ll;
using namespace std;
void init(ll a,ll b){
    cin >> a >> b;
    cout << a+b <<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    init(a,b);
    return 0;
}

也可以用匿名函数(不过用支持auto的

C++
#include<iostream>
typedef long long ll;
using namespace std;
int main(){
    ll a,b;
    cin >> a >> b;
    auto add = [](ll a,ll b){return a+b;};
    cout << add(a,b);
    return 0;
}
原文