社区讨论

请帮我填一下空,我看不懂

灌水区参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@lo2d079d
此快照首次捕获于
2023/10/23 11:49
2 年前
此快照最后确认于
2023/11/03 11:58
2 年前
查看原帖
给定一个正整数数组 arr ,将数组 arr 中的一个连续子序列称作 arr 的子数组。
要求用户输入数组长度和数组内容,输出数组 arr 中所有长度为奇数的子数组中各元素的和。
注意:勿改动预留代码中 main() 函数中的内容,只需将 sumLengthSubarrays(vector& arr) 函数补充完整。
样例:
输入:5 1 4 2 5 3
输出:58
CPP
#include <iostream>
#include <cmath>
#include <set>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
int sumLengthSubarrays(vector<int>& arr) {
    
}
int main(){
    vector<int>arr;
	int n;
	cin >> n;
	int b;
	for(int i = 0;i < n;i++){
		cin >> b;
		arr.push_back(b);
	}
	cout<<sumLengthSubarrays(arr);
	return 0;
}  

回复

4 条回复,欢迎继续交流。

正在加载回复...