数列极差问题(the problem of sequence biggest difference)
#include <iostream>
#include <string>
#include <list> //we use the list container , because it is easy to sort and get the biggest number and smallest number
using namespace std;
void sequenceBiggestLess(list<int> a, list<int> b)
{
a.sort();
b.sort();
int temp1, temp2;
while(a.size()!=1)
{
//get the biggest number
temp1 = a.front();
a.pop_front();
temp2 = a.front();
a.pop_front();
temp1 = temp1 * temp2 + 1;
a.push_back(temp1);
a.sort();
//get the smallest number
temp1 = b.back();
b.pop_back();
temp2 = b.back();
b.pop_back();
temp1 = temp1 * temp2 + 1;
b.push_back(temp1);
b.sort();
}
temp1 = a.front();
temp2 = b.front();
cout << "biggest value: "<< temp1-temp2;
}
int main()
{
list<int> a, b;
cout << "please input the numbers you wanted to calculate\n enter the number of numbers\n";
int n;
cin >> n;
int temp;
for(int i=0; i<n; i++)
{
cin >> temp;
a.push_back(temp);
b.push_back(temp);
}
sequenceBiggestLess(a, b);
return 0;
}
转载于:https://www.cnblogs.com/1915884031A-qqcom/p/7576095.html
- 点赞
- 收藏
- 分享
- 文章举报
- The Overview of Rule Placement Problem in SDN(规则放置问题的概述)
- What are some of the differences between using recursion to solve a problem versus using iteration?
- 机器学习(四)正则化与过拟合问题 Regularization / The Problem of Overfitting
- The problem of the user is not associated with a trusted sql server connection 混合登录选项设置的问题
- 表扩展失败(ORA-01653)后的空间管理问题【THE SPACE MANAGEMENT PROBLEM OF THE TABLE EXTEND FAILD 】 推荐
- 解决yum升级的问题“There was a problem importing one of the Python modules”
- Error:A problem was found with the configuration of task ':app:packageDebug' 问题解决
- The biggest problem of mobile ip
- Error:A problem was found with the configuration of task ':app:packageDebug' 问题解决
- 欧拉项目 Problem 25 of in the Fibonacci sequence to contain 1000 digits
- The problem of the user is not associated with a trusted sql server connection 混合登录选项设置的问题
- 编程之美 拒绝玄学 将帅问题简明解The problem of chinese chess about generals
- 解决yum升级的问题“There was a problem importing one of the Python modules”
- 解决yum升级的问题“There was a problem importing one of the Python modules”
- TCP 粘包问题处理[2] ( the solution of sticky package problem of TCP )
- The problem of maze(经典迷宫问题) DFS版
- Error:A problem was found with the configuration of task ':app:packageDebug' 问题解决
- 配置问题: Could not find a version of the boost date_time library!
- eclipse中出现Resource is out of sync with the file system问题
- 寻找最近点对问题(FCPP find the closest pair of point)