c2
This commit is contained in:
parent
0d75f30a49
commit
4744ebb565
69 changed files with 7 additions and 5 deletions
30
1sem/adaptation courses/08/24.cpp
Normal file
30
1sem/adaptation courses/08/24.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// ac_8_24.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
vector<int> two_mins(const vector<int> &vec) {
|
||||
vector<int> v = vec;
|
||||
sort(begin(v), end(v));
|
||||
v.resize(2);
|
||||
return v;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
cout << "N >>>";
|
||||
cin >> N;
|
||||
vector<int> v;
|
||||
v.reserve(N);
|
||||
cout << "v[...] >>>";
|
||||
for (int i = 0; i < N; i++) {
|
||||
int j;
|
||||
cin >> j;
|
||||
v.push_back(j);
|
||||
}
|
||||
vector<int> nv = two_mins(v);
|
||||
cout << "Two minimals is " << nv[0] << " and " << nv[1] << endl;
|
||||
return 0;
|
||||
}
|
||||
33
1sem/adaptation courses/08/25.cpp
Normal file
33
1sem/adaptation courses/08/25.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// ac_8_25.cpp
|
||||
// Горбацевич Андрей
|
||||
#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));
|
||||
swap(*(v.end() - 1), v[1]);
|
||||
v.resize(2);
|
||||
return v;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
cout << "N >>>";
|
||||
cin >> N;
|
||||
vector<int> v;
|
||||
v.reserve(N);
|
||||
srand(time(0));
|
||||
for (int i = 0; i < N; i++) {
|
||||
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;
|
||||
}
|
||||
40
1sem/adaptation courses/08/26.cpp
Normal file
40
1sem/adaptation courses/08/26.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// ac_8_26.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
vector<int> count_less(const vector<int> &vec, int h) {
|
||||
vector<int> v;
|
||||
v.reserve(vec.size());
|
||||
for (size_t c = 0; c < vec.size(); c++) {
|
||||
if (vec[c] < h) {
|
||||
v.push_back(c);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
cout << "N >>>";
|
||||
cin >> N;
|
||||
vector<int> heights;
|
||||
heights.reserve(N);
|
||||
cout << "heights[...] >>>";
|
||||
for (int i = 0; i < N; i++) {
|
||||
int j;
|
||||
cin >> j;
|
||||
heights.push_back(j);
|
||||
}
|
||||
int h;
|
||||
cout << "h >>>";
|
||||
cin >> h;
|
||||
vector<int> nv = count_less(heights, h);
|
||||
cout << "Lesser indexes: ";
|
||||
for (int ch : nv) {
|
||||
cout << ch << " ";
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue