some tasks
This commit is contained in:
+30
-13
@@ -1,22 +1,39 @@
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
void process(const std::vector<int>& mas1, std::vector<int>& mas2) {
|
||||
std::set<int> set1(mas1.begin(), mas1.end());
|
||||
void process(const std::vector<int>& v1, std::vector<int>& v2) {
|
||||
std::vector<int> copy_v1(v1);
|
||||
std::sort(copy_v1.begin(), copy_v1.end());
|
||||
auto last = std::unique(copy_v1.begin(), copy_v1.end());
|
||||
copy_v1.erase(last, copy_v1.end());
|
||||
|
||||
if (set1.empty() || mas2.empty()) {
|
||||
return;
|
||||
}
|
||||
auto iter = --v2.end();
|
||||
int num = (int)v2.size() - 1;
|
||||
|
||||
for (auto it = mas2.end() - 1; it != mas2.begin() - 1; --it) {
|
||||
int dst = it - mas2.begin();
|
||||
|
||||
if (std::find(set1.begin(), set1.end(), dst) != set1.end()) {
|
||||
mas2.erase(it);
|
||||
while (iter != --v2.begin()) {
|
||||
if (std::binary_search(copy_v1.begin(), copy_v1.end(), num)) {
|
||||
iter = v2.erase(iter);
|
||||
}
|
||||
|
||||
num--;
|
||||
iter--;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #include <iostream>
|
||||
// int main() {
|
||||
// std::vector<int> v1 = { 0, 2, 4, 10, -6, 2, 2, 4 };
|
||||
// std::vector<int> v2 = { 0, 2, 4, 10, -6, 2, 2, 4 };
|
||||
|
||||
// process(v1, v2);
|
||||
|
||||
// for (auto& i : v2) {
|
||||
// std::cout << i << " ";
|
||||
// }
|
||||
// std::cout << std::endl;
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
Reference in New Issue
Block a user