some tasks

This commit is contained in:
2025-05-03 01:17:58 +03:00
parent 6e8e69728e
commit 689b148736
5 changed files with 149 additions and 19 deletions
+30 -13
View File
@@ -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;
// }
+45
View File
@@ -0,0 +1,45 @@
#include <list>
#include <iostream>
int main() {
std::list<int> l;
int n;
std::cin >> n;
while (n != 0) {
l.push_back(n);
std::cin >> n;
}
while (std::cin >> n) {
auto iter = l.begin();
if (n < 0) {
n = abs(++n);
if ((size_t)n >= l.size()) {
continue;
}
while (n--) ++iter;
l.erase(iter);
} else {
int tmp;
std::cin >> tmp;
--n;
while (n-- && iter != l.end()) ++iter;
l.insert(iter, tmp);
// l.insert();
}
}
for (auto& i : l) {
std::cout << i << std::endl;
}
return 0;
}