From 8dd2e6b8dac0d20a695f929683184de24951f28e Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Mon, 17 Jan 2022 13:11:40 +0800 Subject: [PATCH] add: 220117 (previous is CN) --- 2201/220117.cpp | 30 ++++++++++++++++++++++++++++++ 2201/CMakeLists.txt | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 2201/220117.cpp diff --git a/2201/220117.cpp b/2201/220117.cpp new file mode 100644 index 0000000..efe220c --- /dev/null +++ b/2201/220117.cpp @@ -0,0 +1,30 @@ +#include +#include + +class Solution { +public: + static bool wordPattern(const std::string& pattern, const std::string& s) { + std::string mode[26], t; + std::stringstream sin(s); + for (const auto& i : pattern) { + if (!(sin >> t)) + return false; + if (mode[i - 'a'].empty()) + mode[i - 'a'] = t; + if (mode[i - 'a'] != t) + return false; + int cnt = 0; + for (const auto& j : mode) { + if (j == t) + ++cnt; + } + if (cnt > 1) + return false; + } + return !(sin >> t); + } +}; + +int main() { + return !Solution::wordPattern("abba", "dog cat cat dog"); +} \ No newline at end of file diff --git a/2201/CMakeLists.txt b/2201/CMakeLists.txt index 89bead9..8f9a4a7 100644 --- a/2201/CMakeLists.txt +++ b/2201/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2201) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2201 220117-CN.cpp) \ No newline at end of file +ADD_EXECUTABLE(2201 220117.cpp) \ No newline at end of file