-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisomorphic_strings.cpp
More file actions
62 lines (47 loc) · 1.27 KB
/
isomorphic_strings.cpp
File metadata and controls
62 lines (47 loc) · 1.27 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include"essentials.cpp"
bool isIsomorphic(string s, string t) {
map<char,set<char> >mp1;
if(s.length()!=t.length()){
return false;
}
for(int i=0;i<s.length();i++){
{
mp1[s[i]].insert(t[i]);
}
}
// for(auto it:mp1){
// cout<<it.first<<endl;
// for(auto it1:it.second){
// cout<<it1<<endl;
// }
// }
bool flag =true;
bool flag1 =true;
for(auto it:mp1){
if(it.second.size()!=1){
flag=false;
}
}
if(flag==false){
return false;
}
else{
for(auto it=mp1.begin();it!=prev(mp1.end());it++){
// cout<<it->second[0]<<endl;
set<char>set1=it->second;
for(auto it1=next(it);it1!=mp1.end();it1++){
set<char>set2=it1->second;
if(set1==set2){
flag1=false;
}
}
}
}
return (flag && flag1);
}
int main(){
string s="ab";
string t="aa";
cout<<isIsomorphic(s,t)<<endl;
return 1;
}