using System.Collections.Generic;
static bool CharactersMatch(string word1, string word2, bool exact=false)
if (word1.Length != word2.Length)
Dictionary<char, int> occurrences = new Dictionary<char, int>();
for (int i = 0; i < word1.Length; i++)
if (!occurrences.ContainsKey(word1[i]))
occurrences[word1[i]] = 0;
if (!occurrences.ContainsKey(word2[i]))
occurrences[word2[i]] = 0;
Console.WriteLine(occurrences.Sum(x => x.Value));
if (occurrences.Sum(x => x.Value) == occurrences.Count * 2)
public static void Main()
Console.WriteLine(CharactersMatch("cateeeee", "tacee"));