using System;
using System.Collections.Generic;
namespace sticks
{
class Program
{
// Stick[] stores the count
// of sticks required to
// represent the alphabets
public static int[] sticks = { 6, 7, 4, 6, 5, 4, 6,
5, 2, 4, 4, 3, 6, 6,
6, 5, 7, 6, 5, 3, 5,
4, 6, 4, 3, 4 };
// Number[] stores the count
// of sticks required to
// represent the numerals
public static int[] number = { 6, 2, 5, 5, 4, 5, 6,
3, 7, 6 };
// Function that return the count of
// sticks required to represent
// the given string str
public static int countSticks(string str)
{
int cnt = 0;
// Loop to iterate over every
// character of the string
for (int i = 0; i < str.Length; i++)
{
char ch = str[i];
// Add the count of sticks
// required to represent the
// current character
if (ch >= 'A' && ch <= 'Z')
{
cnt += sticks[ch - 'A'];
}
else
{
cnt += number[ch - '0'];
}
}
return cnt;
}
// Function to sort the array
// according to the number of
// sticks required to represent it
public static void sortArr(string[] arr, int n)
{
// Vector to store the number
// of sticks required with
// respective strings
List<KeyValuePair<int, string>> vp = new List<KeyValuePair<int, string>>();
// Inserting number of sticks
// with respective strings
for (int i = 0; i < n; i++)
{
vp.Add(new KeyValuePair<int, string>(countSticks(arr[i]), arr[i]));
}
// Sort the vector,
vp.Sort((x, y) => x.Key.CompareTo(y.Key));
// Print the sorted vector
for (int i = 0; i < vp.Count; i++)
Console.Write($"{vp[i].Value} ");
Console.WriteLine();
}
static void Main(string[] args)
{
string[] arr = { "GEEKS", "FOR",
"GEEKSFORGEEKS" };
int n = arr.Length;
sortArr(arr, n);
}
}
}
// This code is contributed by ruchikabaslas