#include <iostream> #include <vector> #include <string> #include <unorderedmap> #include…
- User
#include #include #include #include <unordered_map> #include <unordered_set> #include #include
using namespace std;
int f(int a, vector& b, string c) { unordered_map<string, vector<pair<vector, int>>> d; for (auto& e : b) { size_t pos = e.find('='); string g = e.substr(0, pos); string h = e.substr(pos + 1); vector k; size_t start = 0; while ((pos = h.find('+', start)) != string::npos) { k.push_back(h.substr(start, pos - start)); start = pos + 1; } k.push_back(h.substr(start)); int l = k.size() - 1; d[g].push_back(make_pair(k, l)); } queue m; unordered_map<string, int> n; unordered_set o; unordered_set p;
for (const auto& q : d) { p.insert(q.first); for (const auto& r : q.second) { for (const auto& s : r.first) { o.insert(s); } } } for (const auto& t : o) { if (p.find(t) == p.end()) { n[t] = 0; m.push(t); } } while (!m.empty()) { string u = m.front(); m.pop(); int v = n[u]; for (auto& w : d) { string x = w.first; auto& y = w.second; for (auto& z : y) { auto& aa = z.first; int ab = z.second; if (find(aa.begin(), aa.end(), u) != aa.end()) { bool ac = true; for (auto& ad : aa) { if (n.find(ad) == n.end()) { ac = false; break; } } if (ac) { int ae = ab; for (auto& af : aa) { ae += n[af]; } if (n.find(x) == n.end() || ae < n[x]) { n[x] = ae; m.push(x); } } } } } } if (n.find(c) != n.end()) { return n[c]; } return INT_MAX;}
int main() { int a; cin >> a; vector b(a); for (int i = 0; i < a; ++i) { string temp; cin >> ws;
getline(cin, temp); b[i] = temp;
} string c; cin >> ws;
cin >> c; cout << f(a, b, c) << endl; return 0; } - Assistant
This C++ code represents a function that solves a problem involving symbolic equations and the computation of minimal values. Let's break down the key components and the workflow of the code:
- User
b.cpp: In function 'int f(int, std::vector >&, std::string)': b.cpp:60:25: error: no matching function for call to 'find(std::vector >::iterator, std::vector >::iterator, std::string&)' 60 | if (find(aa.begin(), aa.end(), u) != aa.end()) { | ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/bits/locale_facets.h:48, from /usr/include/c++/11/bits/basic_ios.h:37, from /usr/include/c++/11/ios:44, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from b.cpp:2: /usr/include/c++/11/bits/streambuf_iterator.h:421:5: note: candidate: 'template typename __gnu_cxx::__enable_if::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >, const _CharT2&)' 421 | find(istreambuf_iterator<_CharT> __first, | ^~~~ /usr/include/c++/11/bits/streambuf_iterator.h:421:5: note: template argument deduction/substitution failed: b.cpp:60:25: note: '__gnu_cxx::__normal_iterator*, std::vector > >' is not derived from 'std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >' 60 | if (find(aa.begin(), aa.end(), u) != aa.end()) { | ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
- Assistant
The error message you're encountering is due to the improper use of the
findfunction template. Thefindfunction is part of the<algorithm>library and is used to find an element in a sequence. Your code seems to have issues because it doesn't recognize thefindfunction for a standard vector.To resolve this issue, you should include the
<algorithm>header at the beginning of your file. This header contains the declaration for thefindalgorithm, which is needed for the code to compile correctly.Here’s how you can modify your code to fix the error:
-
Include the Header for Algorithms:
-