#include <iostream> #include <map> #ifdef DEBUG #define DEBUG_LOG(x) do { \ std::cerr << x << std::endl;\ } while (0) #else #define DEBUG_LOG(x) do { \ } while (0) #endif struct TaskSet { std::map<std::string, uint64_t> tasks = {}; void FillMapWith(uint64_t val, int start, int end) { for (int i = start; i <= end; ++i) { for (char c = 'A'; c <= 'C'; ++c) { std::string name = std::to_string(i) + c; tasks.insert(std::pair<std::string, uint64_t>(name, val)); } } } void Reset() { FillMapWith(0,1,5); } friend std::ostream& operator<<(std::ostream& stream, TaskSet const & taskSet) { for (auto const& task: taskSet.tasks) { stream << task.first << " : " << task.second << "\n"; } return stream; } void AppendTask(std::string const & task) { tasks[task] += 1; } bool operator>=(TaskSet const& rhs) const { auto pred =[] (decltype(*rhs.tasks.begin()) l, decltype(l) r) { return (l.first == r.first) && (l.second >= r.second); }; return std::equal(std::begin(tasks), std::end(tasks), std::begin(rhs.tasks), pred); } }; void Run(std::istream& input, std::ostream& output) { TaskSet tasks; tasks.Reset(); TaskSet expectedTasks; expectedTasks.FillMapWith(1, 1,4); expectedTasks.FillMapWith(2, 5,5); DEBUG_LOG(expectedTasks); uint64_t num = 0; input >> num; for (int i =0; i < num; ++i) { std::string task = ""; input >> task; tasks.AppendTask(task); } DEBUG_LOG(tasks); if(tasks >= expectedTasks) { DEBUG_LOG("true"); output << "TAK" << std::endl; } else { DEBUG_LOG("false"); output << "NIE" << std::endl; } } #ifndef DEBUG int main(int argc, char* argv[]) #else int main_(int argc, char* argv[]) #endif { ::Run(std::cin, std::cout); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | #include <iostream> #include <map> #ifdef DEBUG #define DEBUG_LOG(x) do { \ std::cerr << x << std::endl;\ } while (0) #else #define DEBUG_LOG(x) do { \ } while (0) #endif struct TaskSet { std::map<std::string, uint64_t> tasks = {}; void FillMapWith(uint64_t val, int start, int end) { for (int i = start; i <= end; ++i) { for (char c = 'A'; c <= 'C'; ++c) { std::string name = std::to_string(i) + c; tasks.insert(std::pair<std::string, uint64_t>(name, val)); } } } void Reset() { FillMapWith(0,1,5); } friend std::ostream& operator<<(std::ostream& stream, TaskSet const & taskSet) { for (auto const& task: taskSet.tasks) { stream << task.first << " : " << task.second << "\n"; } return stream; } void AppendTask(std::string const & task) { tasks[task] += 1; } bool operator>=(TaskSet const& rhs) const { auto pred =[] (decltype(*rhs.tasks.begin()) l, decltype(l) r) { return (l.first == r.first) && (l.second >= r.second); }; return std::equal(std::begin(tasks), std::end(tasks), std::begin(rhs.tasks), pred); } }; void Run(std::istream& input, std::ostream& output) { TaskSet tasks; tasks.Reset(); TaskSet expectedTasks; expectedTasks.FillMapWith(1, 1,4); expectedTasks.FillMapWith(2, 5,5); DEBUG_LOG(expectedTasks); uint64_t num = 0; input >> num; for (int i =0; i < num; ++i) { std::string task = ""; input >> task; tasks.AppendTask(task); } DEBUG_LOG(tasks); if(tasks >= expectedTasks) { DEBUG_LOG("true"); output << "TAK" << std::endl; } else { DEBUG_LOG("false"); output << "NIE" << std::endl; } } #ifndef DEBUG int main(int argc, char* argv[]) #else int main_(int argc, char* argv[]) #endif { ::Run(std::cin, std::cout); return 0; } |