Upload project.

This commit is contained in:
Stedos
2020-06-26 13:56:07 +01:00
parent 1e3503a70f
commit d5c5de41ca
14 changed files with 469 additions and 0 deletions

8
Anagram/Anagram.csproj Normal file
View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

37
Anagram/Program.cs Normal file
View File

@@ -0,0 +1,37 @@
using System;
namespace Anagram
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Check("rail safety", "fairy tales")); //Should return true
Console.WriteLine(Check("roast beef", "eat for BSE")); //Should return true (ignores spaces)
Console.WriteLine(Check("DeBiT CaRd", "BAD CREDIT")); //Should return true (ignores case)
Console.WriteLine(Check("empty", "light")); //Should return false (not an anagram)
Console.WriteLine(Check("a", "aa")); //Should return false (not of equal length)
Console.WriteLine(Check("William Shakespeara", "I am a weakish speller")); //Should return false (spelling error)
}
private static bool Check(string s1, string s2)
{
s1 = s1.Replace(" ", String.Empty).ToLower();
s2 = s2.Replace(" ", String.Empty).ToLower();
//If the string lengths aren't equal, they cannot be an anagram.
if (s1.Length != s2.Length)
return false;
while (s1.Length > 0)
{
if (!s2.Contains(s1[0]))
return false;
s2 = s2.Remove(s2.IndexOf(s1[0]), 1);
s1 = s1.Remove(0, 1);
}
return true;
}
}
}