P1001 A+B Problem题解

· · 题解

https://www.luogu.com.cn/problem/P1001

不是那么奇葩的奇葩解

题目大意

输出a和b 求a+b的和;

正解:

#include<bits/ctdc++.h>//万能头文件
using namespace std;
int main(){
    int a,b;//定义变量
    cin >> a >> b;//输入a与b
    cout << a+b;//输出和
    return 0;
}

新手勿看

“奇葩”の解答:

小巫见大巫

蒟蒻很菜,大佬勿喷;

其实只要用前缀和就能轻松解决这道题:

#include <bits/stdc++.h>
using namespace std;
int a[10000010],sum[100000010];
int main(){
    for(int i=1;i<=2;i++){
        cin >> a[i];
        sum[i]=sum[i-1]+a[i];
    }
    cout << sum[2]-sum[0];
return 0;
}