add: 220117 (previous is CN)
This commit is contained in:
parent
e4a6a74e18
commit
8dd2e6b8da
|
|
@ -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");
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2201)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2201 220117-CN.cpp)
|
||||
ADD_EXECUTABLE(2201 220117.cpp)
|
||||
Loading…
Reference in New Issue