Task: | Alitaulukot |
Sender: | _Ahrou |
Submission time: | 2020-10-01 13:43:30 +0300 |
Language: | C++ (C++11) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'std::vector<std::vector<int> > get_sub_tables(std::vector<int>&, int)': input/code.cpp:39:84: error: no matching function for call to 'find(std::vector<std::vector<__gnu_cxx::__normal_iterator<int*, std::vector<int> > > >::iterator, std::vector<std::vector<__gnu_cxx::__normal_iterator<int*, std::vector<int> > > >::iterator, std::vector<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >&)' auto element_loc = std::find(i_sub_tables.begin(), i_sub_tables.end(), table_of_i); ^ In file included from /usr/include/c++/7/bits/locale_facets.h:48:0, from /usr/include/c++/7/bits/basic_ios.h:37, from /usr/include/c++/7/ios:44, from /usr/include/c++/7/ostream:38, from /usr/include/c++/7/iostream:39, from input/code.cpp:1: /usr/include/c++/7/bits/streambuf_iterator.h:369:5: note: candidate: templ...
Code
#include <iostream> #include <vector> #include <cmath> std::vector<std::vector<int>> get_sub_tables(std::vector<int>& table, int difference) { std::vector<std::vector<std::vector<int>::iterator>> i_sub_tables; std::vector<std::vector<int>> sub_tables; for (auto element = table.begin(); element != table.end(); ++element) { std::vector<std::vector<int>::iterator> temp; temp.emplace_back(element); i_sub_tables.emplace_back(temp); } for (auto start_e = table.begin(); start_e != table.end(); ++start_e) { auto min = start_e; for (auto cur_e = start_e + 1; cur_e != table.end(); ++cur_e) { int res = *min - *cur_e; if (std::abs(res) <= difference) { std::vector<std::vector<int>::iterator> temp; for (auto i = start_e; i != cur_e + 1; ++i) { temp.emplace_back(i); } i_sub_tables.emplace_back(temp); } else { break; } } } int counter = 0; for (auto table_of_i : i_sub_tables) { auto element_loc = std::find(i_sub_tables.begin(), i_sub_tables.end(), table_of_i); if (element_loc != i_sub_tables.begin() + counter) { i_sub_tables.erase(i_sub_tables.begin() + counter); } else { std::vector<int> temp; for (auto element : table_of_i) { temp.emplace_back(*element); } sub_tables.emplace_back(temp); } counter++; } return sub_tables; } void print_sub_tables(const std::vector<std::vector<int>>& sub_tables) { for (auto table : sub_tables) { std::cout << "[ "; for (auto element : table) { std::cout << element << " "; } std::cout << "] "; } } int main() { int n; int d; std::vector<int> table; std::cin >> n; std::cin >> d; for (int i = 0; i < n; i++) { int temp; std::cin >> temp; table.emplace_back(temp); } auto sub_tables = get_sub_tables(table, d); print_sub_tables(sub_tables); std::cout << sub_tables.size(); return 0; }