4 ms·
Thanks for checking into that... doesn't look like the AI is even close to ready for prime time right now as this is not the correct translation: #include
by merlincorey 4y ago
Thanks for checking into that... doesn't look like the AI is even close to ready for prime time right now as this is not the correct translation:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
std::map<int, int> foobar(std::vector<int> x, std::vector<int> y) {
std::map<int, int> map;
for (int i = 0; i < x.size(); i++) {
if (std::find(y.begin(), y.end(), x[i]) != y.end()) {
map[x[i]] = x[i + 1];
}
}
return map;
}
int main(int argc, char** argv) {
std::vector<int> ex{ 1, 2, 3, 4 };
std::vector<int> wy{ 3, 4, 5, 6 };
std::map<int, int> result = foobar(ex, wy);
std::cout << "{";
for ( const auto &item : result) {
std::cout << item.first << ": " << item.second << ", ";
}
std::cout << "}" << std::endl;
}
It outputs:
{3: 4, 4: 0, }
But it SHOULD be getting:
{3: 1, 4: 2, }