GetHiddenMessage.cs

CSharp · Console

/Program.cs

using System;
using System.Linq;
using System.Collections.Generic;
					
public class Program
{
	public static string GetHiddenMessage(char[,] puzzle, string[] keys)
	{
		List<char> charList = puzzle.Cast<char>().ToList();
		foreach(string key in keys)
		{
			for (int i = 0; i < key.Length; i++)
			{
				if (charList.Contains(key[i]))
				{
					charList.Remove(key[i]);
				}
			}
		}

		return new string(charList.ToArray());
	}
	
	public static void Main()
	{
		Console.WriteLine("UniLecs");
		char[,] puzzle = new char[,]
		{
			{ 'U', 'T', 'H', 'E' },
			{ 'N', 'A', 'S', 'K' },
			{ 'I', 'L', 'E', 'C' },
			{ 'L', 'L', 'O', 'S' }
		};
		string[] keys = new string[]
		{
			"TASK", 
			"UNILECS"
		};
		Console.WriteLine(string.Format("Answer = {0}", GetHiddenMessage(puzzle, keys))); // HELLO		
	}
}
;