-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
41 lines (38 loc) · 828 Bytes
/
program.cpp
File metadata and controls
41 lines (38 loc) · 828 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
32
33
34
35
36
37
38
39
40
41
#include "../include/pre.h"
bool isIsomorphic(string s, string t)
{
assert(s.length() == t.length());
int feature_s[255]; int top_s = 0;
int feature_t[255]; int top_t = 0;
for (int i = 0; i != 255; i++)
{
feature_s[i] = 0;
feature_t[i] = 0;
}
auto it_s = s.begin();
auto it_t = t.begin();
while (it_s != s.end())
{
if (feature_s[it_s[0]] == 0)
{
feature_s[it_s[0]] = ++top_s;
}
int var_s = feature_s[it_s[0]];
if (feature_t[it_t[0]] == 0)
{
feature_t[it_t[0]] = ++top_t;
}
int var_t = feature_t[it_t[0]];
if (var_s != var_t)
return false;
it_s++;
it_t++;
}
return true;
}
int Mymain()
{
cout \
<< isIsomorphic("egg", "lkk") << ", " \
<< isIsomorphic("kdsjaf", "oigjhk") << ", ";
}