CheckWordSquare.cs

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
					
public class Program
{
	public static bool CheckWordSquare(List<string> words) {
        int len = words.Count;
         
        for(int i = 0; i < len; i++)
        {
            for(int j = 0; j < words[i].Length; j++)
            {
                if (j >= len || words[j].Length <= i || words[j][i] != words[i][j])
                    return false;
            }
        }

        return true;
    }
	
	public static void Main()
	{
		Console.WriteLine("UniLecs");
		
		// tests
		Console.WriteLine(CheckWordSquare(new List<string>() { "abcd", "bnrt", "crm", "dt" })); // true
		Console.WriteLine(CheckWordSquare(new List<string>() { "ball","area","read","lady" })); // false
	}
}
;