| Task: | Alitaulukot |
| Sender: | _Ahrou |
| Submission time: | 2020-10-01 10:54:35 +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:12:58: error: no matching function for call to 'find(std::vector<std::vector<int> >::iterator, std::vector<std::vector<int> >::iterator, std::vector<int>&)'
if(std::find(sub_tables.begin(), sub_tables.end(), temp) == std::end(sub_tables))
^
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: template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istr...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<int>> sub_tables;
for (auto i : table)
{
std::vector<int> temp;
temp.emplace_back(i);
if(std::find(sub_tables.begin(), sub_tables.end(), temp) == std::end(sub_tables))
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<int> temp;
for (auto i = start_e; i != cur_e + 1; ++i)
{
temp.emplace_back(*i);
}
if(std::find(sub_tables.begin(), sub_tables.end(), temp) == std::end(sub_tables))
sub_tables.emplace_back(temp);
}
else
{
break;
}
}
}
return sub_tables;
}
void print_tables(const std::vector<std::vector<int>>& source)
{
for (auto table : source)
{
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_tables(sub_tables);
std::cout << sub_tables.size();
return 0;
}