Odpowiedź:
#include <iostream>
#include <string>
#include <vector>
bool isAnanym(const std::string &a, std::string b) {
std::reverse(b.begin(), b.end());
return a == b;
}
std::vector<std::string> hasNoAnanym(const std::vector<std::string> &words) {
std::vector<std::string> result;
bool hasAnanym = false;
for (int i = 0; i < words.size(); i++) {
for (int j = 0; j < words.size(); j++) {
if (isAnanym(words[i], words[j])) {
hasAnanym = true;
break;
}
}
if (!hasAnanym) {
result.push_back(words[i]);
}
hasAnanym = false;
}
return result;
}
int main() {
std::vector<std::string> words = {"bard", "mleko", "pies", "drab", "okno", "koks", "ucho", "skok"};
auto res = hasNoAnanym(words);
for (const auto &word: res) {
std::cout << word << std::endl;
}
return 0;
}
Wyjaśnienie:
Jak czegoś nie wiesz to pytaj