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