add: 220117 (previous is CN)

This commit is contained in:
Lam Haoyin 2022-01-17 13:11:40 +08:00
parent e4a6a74e18
commit 8dd2e6b8da
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 31 additions and 1 deletions

30
2201/220117.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <string>
#include <sstream>
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");
}

View File

@ -3,4 +3,4 @@ PROJECT(2201)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2201 220117-CN.cpp) ADD_EXECUTABLE(2201 220117.cpp)