求出数组中相邻三个数之和最大的~
2010-03-24 09:49
232 查看
// 求出数组中相邻三个数之和最大的一组 #include "stdafx.h" #include <stdio.h> #include <math.h> #include <iostream> #include <String> using namespace std; int main() { // 输入数组的最大值 int array_size = 100; cout<<"please input the array_size of the array : "; cin>>array_size; int num[10000]; for(int i = 0; i < array_size; i++) { num[i] = rand() % (array_size + 1); cout<< i <<" the random number is :"<<num[i]<<endl; } // 保存最大的值 int max_num = 0; int max_index = 0; for(int i=0; i<array_size - 2; i++) { int temp_max = 0; for(int j=i; j<i+3; j++) { temp_max += num[j]; } if(temp_max > max_num) { max_num = temp_max; max_index = i; } } cout<<"the max num of the three in the array is :"<<max_num<<endl; cout<<"the max num index of the array is : "<<max_index<<endl; system("pause"); }
相关文章推荐
- 找出数组中任何相邻子向量的最大和
- 求一个数组中三个最大值的下标
- 三个递增的整形数组中找到最大的公共元素
- LeetCode-198. House Robber (JAVA)寻找数组不相邻组合最大值DP
- 无序数组排序后的最大相邻差值求解
- 1.将数组A中的内容和数组B中的内容进行交换。(数组一样大) 2.获取一个数二进制序列中所有的偶数位和奇数位,分别输出二进制序列。 3.将三个数按从大到小输出。 4.求两个数的最大公约数。
- 动态规划求不相邻的最大子数组和
- 给一个整数数组,有正有负。找出数组最大和,条件是使用的元素不能有相邻
- 排序后数组中相邻两数的最大值
- 结对开发,首位相邻的数组求最大子数组
- 给定一个无序数组,排序之后求相邻两数之间的最大差值
- 从数组中找出乘积最大的三个数
- 一个无序实数数组中的相邻两个元素的最大差值
- 动态规划求不相邻的最大子数组和
- [LeetCode] Maximum Sum of 3 Non-Overlapping Subarrays 三个非重叠子数组的最大和
- 桶---求无序数组排序后,最大的相邻差值
- 求无序数组排序后相邻俩数最大差值(思路及详解)
- LeetCode—House Robber 寻找数组不相邻组合最大值DP
- 求数组相邻元素差值的最大值快速算法(C++版)
- 无序数组的相邻最大差值