要求:
1.输入每个点的糖果数目
2.a先选,然后b在a选择列表之后选择糖果
3.求a和b的差值的最大值
代码:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int>lisa;
int s, suppose, n = 0, temp = 0;
cout << "输入数据,‘#’结尾" << endl;
while (cin >> s)
{
lisa.push_back(s);
++n;
}
auto a = lisa.begin();
auto b = lisa.end();
for (int i = 0; i < n; ++i)
{
for (int j = i + 1; j < n; ++j)
{
suppose = (*(a + i) - *(a + j)) > 0 ? *(a + i) - *(a + j) : *(a + j) - *(a + i);
temp = suppose>temp ? suppose : temp;
}
}
if (cout << "最大差值:" << temp << endl)
cout << "m_geek 你最帅!" << endl;
else cout << "呸!m_geek 你个臭屌丝!" << endl;
system("pause");
return 0;
}
结果: