-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
31 lines (29 loc) · 720 Bytes
/
program.cpp
File metadata and controls
31 lines (29 loc) · 720 Bytes
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
#include "../include/pre.h"
#include <set>
const size_t MAXPATTERN = 26;
bool wordPattern(string pattern, string str)
{
string dict[MAXPATTERN];
std::set<string> strPool;
std::stringstream ss{str};
string tmp;
for (auto p : pattern)
{
if (ss.eof()) return false;
ss >> tmp;
if (dict[p - 'a'] == "") {
if (strPool.find(tmp) != strPool.end()) return false;
strPool.insert(tmp);
dict[p - 'a'] = tmp;
continue;
}
if (dict[p - 'a'] != tmp) return false;
}
if (!ss.eof()) return false;
return true;
}
int main()
{
cout << std::boolalpha << wordPattern("abcd", "as as erqw dfsa");
return 0;
}