using
System;
using
System.Collections.Generic;
public
class
GFG
{
static
bool
isPowerOfTwo(
int
n)
{
if
(n == 0)
return
false
;
return
(Math.Ceiling(Math.Log(n) / Math.Log(2)) ==
Math.Floor(Math.Log(n) / Math.Log(2)));
}
static
void
printArray(List<
string
> res)
{
(res).Sort();
for
(
int
i = 0; i < res.Count; i++)
{
Console.Write(res[i] +
" "
);
}
}
static
void
sortedStrings(
string
[] S,
int
N)
{
Dictionary<
char
,
int
> freq =
new
Dictionary<
char
,
int
>();
List<
string
> res =
new
List<
string
>();
for
(
int
i = 0; i < N; i++)
{
string
st =
""
;
for
(
int
j = 0; j < S[i].Length; j++)
{
if
(!freq.ContainsKey(S[i][j]))
freq.Add(S[i][j],0);
freq[S[i][j]]++;
}
foreach
(KeyValuePair<
char
,
int
> ch
in
freq)
{
if
(isPowerOfTwo(freq[ch.Key]))
{
for
(
int
j = 0; j < freq[ch.Key]; j++)
{
st += ch.Key;
}
}
}
freq.Clear();
if
(st.Length == 0)
continue
;
char
[] myCharArr = st.ToCharArray();
Array.Sort(myCharArr);
string
ns =
""
;
for
(
int
j = myCharArr.Length - 1; j >= 0; --j)
ns += myCharArr[j];
res.Add(ns);
}
printArray(res);
}
static
public
void
Main ()
{
string
[] arr = {
"aaacbb"
,
"geeks"
,
"aaa"
};
int
N = arr.Length;
sortedStrings(arr, N);
}
}