using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Collections;
public
class
GFG
{
class
DisjSet
{
public
int
[] rank;
public
int
[] parent;
public
int
n;
public
DisjSet(
int
n)
{
this
.rank =
new
int
[n];
this
.parent =
new
int
[n];
this
.n = n;
this
.makeSet();
}
public
void
makeSet()
{
for
(
int
i = 0; i <
this
.n; i++)
{
this
.parent[i] = i;
}
}
public
int
find(
int
x)
{
if
(
this
.parent[x] != x)
{
this
.parent[x] =
this
.find(
this
.parent[x]);
}
return
this
.parent[x];
}
public
void
Union(
int
x,
int
y)
{
var
xset =
this
.find(x);
var
yset =
this
.find(y);
if
(xset == yset)
{
return
;
}
if
(
this
.rank[xset] <
this
.rank[yset])
{
this
.parent[xset] = yset;
}
else
if
(
this
.rank[xset] >
this
.rank[yset])
{
this
.parent[yset] = xset;
}
else
{
this
.parent[yset] = xset;
this
.rank[xset] =
this
.rank[xset] + 1;
}
}
}
public
static
List<List<String>> printTransitive(String str1, String str2, String str3)
{
var
obj =
new
DisjSet(26);
var
ans =
new
List<List<String>>();
if
(str1.Length != str2.Length)
{
var
temp =
new
List<String>();
temp.Add(
"All characters"
);
temp.Add(
"not mapped"
);
ans.Add(temp);
return
ans;
}
var
temp1 =
new
List<String>();
temp1.Add(
""
);
temp1.Add(
""
);
ans.Add(temp1);
for
(
int
i = 0; i < str1.Length; i++)
{
obj.Union((
int
)(str1[i]) - 97, (
int
)(str2[i]) - 97);
}
for
(
int
i = 0; i < str3.Length; i++)
{
for
(
char
j =
'a'
; j <=
'z'
; j++)
{
if
(obj.find((
int
)(str3[i]) - 97) == obj.find((
int
)(j) - 97))
{
var
st = ans[0][0];
ans[0][0] = st + j.ToString();
break
;
}
}
for
(
char
j =
'z'
; j >=
'a'
; j--)
{
if
(obj.find((
int
)(str3[i]) - 97) == obj.find((
int
)(j) - 97))
{
var
st = ans[0][1];
ans[0][1] = st + j.ToString();
break
;
}
}
}
return
ans;
}
public
static
void
Main(String[] args)
{
var
str1 =
"geeksgeeks"
;
var
str2 =
"dedication"
;
var
str3 =
"truegeek"
;
var
result = GFG.printTransitive(str1, str2, str3);
Console.WriteLine(result[0][0] +
" "
+ result[0][1]);
}
}