|
|
вернуться в форумWhy do I get WA 1??? Послано Bebop 22 ноя 2020 09:33 #include <iostream> #include <string> #include <vector> #include <set> const std::string &solution(const std::vector<std::string> &penguins); int main() { int n; std::cin >> n; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::vector<std::string> penguins; penguins.reserve(n); for (int i = 0; i < n; ++i) { std::string penguin; std::getline(std::cin, penguin); penguins.emplace_back(std::move(penguin)); } std::cout << solution(penguins) << std::endl; return 0; } const std::string &solution(const std::vector<std::string> &penguins) { std::set<std::string> penguinSet(penguins.begin(), penguins.end()); auto setIterator = penguinSet.begin(); std::set<std::string>::iterator mostNumerous; int maxCount = 0; while (setIterator != penguinSet.end()) { int count = 0; for (const auto &penguin : penguins) { if (*setIterator == penguin) { count++; } } if (count > maxCount) { maxCount = count; mostNumerous = setIterator; } setIterator++; } return *mostNumerous; } I tested locally and it works... |
|
|