using System.Collections.Generic;
public static void Main()
BalanceWords("CoNSUBsTANTiATIoN", "WRONGHEADED", "UNINTELLIGIBILITY", "SUPERGLUE");
public static void BalanceWords(params string[] words)
foreach(var word in words)
public static void BalanceWord(string word)
var upperWord = word.ToUpperInvariant();
var weightedCharacters = new List<Tuple<char,int>>();
foreach (var character in upperWord)
weightedCharacters.Add(new Tuple<char,int>(character, character - 64));
for (int balanceIndex = 0; balanceIndex < word.Length; balanceIndex++)
var leftWeight = CalculLeftWeight(balanceIndex, weightedCharacters);
var rightWeight = CalculRightWeight(balanceIndex, weightedCharacters);
if (leftWeight == rightWeight)
Console.WriteLine("The word : '{0}' is balanced on the letter '{1}' with a weight of '{2}' on each side", word, word[balanceIndex], leftWeight);
else if (leftWeight > rightWeight)
Console.WriteLine("The word : '{0}' can't be balanced.", word);
private static int CalculLeftWeight(int balanceIndex, List<Tuple<char,int>> weightedCharacters)
for (int i = balanceIndex; i >= 0; i--)
leftWeight += ((Tuple<char,int>)weightedCharacters[i]).Item2 * multiplier;
private static int CalculRightWeight(int balanceIndex, List<Tuple<char,int>> weightedCharacters)
for (int i = balanceIndex; i < weightedCharacters.Count; i++)
rightWeight += ((Tuple<char,int>)weightedCharacters[i]).Item2 * multiplier;