Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created October 23, 2023 01:27
Show Gist options
  • Save unilecs/06daa2fc302d2b7f0f1630b8d4c523df to your computer and use it in GitHub Desktop.
Save unilecs/06daa2fc302d2b7f0f1630b8d4c523df to your computer and use it in GitHub Desktop.
Задача: Квадрад слов
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment