c2
This commit is contained in:
parent
0d75f30a49
commit
4744ebb565
69 changed files with 7 additions and 5 deletions
|
|
@ -3,11 +3,12 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
vector<int> max_diff(const vector<int> &vec) {
|
||||
vector<int> v = vec;
|
||||
sort(begin(v), end(v));\
|
||||
sort(begin(v), end(v));
|
||||
swap(*(v.end() - 1), v[1]);
|
||||
v.resize(2);
|
||||
return v;
|
||||
|
|
@ -19,13 +20,14 @@ int main() {
|
|||
cin >> N;
|
||||
vector<int> v;
|
||||
v.reserve(N);
|
||||
cout << "v[...] >>>";
|
||||
srand(time(0));
|
||||
for (int i = 0; i < N; i++) {
|
||||
int j;
|
||||
cin >> j;
|
||||
int j = -5 + rand() % 10;
|
||||
cout << j << " ";
|
||||
v.push_back(j);
|
||||
}
|
||||
cout << endl;
|
||||
vector<int> nv = max_diff(v);
|
||||
cout << "Biggest diff is between " << nv[0] << " and " << nv[1] << " (eq. " << nv[0] - nv[1] << ")" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue