using
System;
using
System.Collections.Generic;
public
class
GFG {
public
static
int
cmp(KeyValuePair<
int
,
string
> x,
KeyValuePair<
int
,
string
> y)
{
if
(x.Key < y.Key) {
return
1;
}
else
if
(x.Key > y.Key) {
return
1;
}
else
{
if
(x.Value.Length < y.Value.Length) {
return
1;
}
}
return
-1;
}
public
static
void
printArraystring(
string
[] str,
int
n)
{
var
m =
new
Dictionary<
string
,
int
>();
for
(
int
i = 0; i < n; i++) {
if
(m.ContainsKey(str[i]))
m[str[i]] = m[str[i]] + 1;
else
m[str[i]] = 1;
}
var
vec =
new
List<KeyValuePair<
int
,
string
> >();
foreach
(KeyValuePair<
string
,
int
> entry
in
m)
{
vec.Add(
new
KeyValuePair<
int
,
string
>(
entry.Value, entry.Key));
}
vec.Sort(cmp);
for
(
int
i = 0; i < vec.Count; i++) {
Console.Write(vec[i].Value +
", "
);
}
}
static
public
void
Main()
{
string
[] arr
= {
"Geeks"
,
"for"
,
"Geeks"
,
"for"
,
"arc"
};
int
n = arr.Length;
printArraystring(arr, n);
}
}