Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
isanagram
using Microsoft.VisualStudio.TestTools.UnitTesting; using ConsoleAppNunit; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace rextester { [TestClass()] public class ProgramTests { [TestMethod()] public void ISAnagramTest() { Assert.IsTrue(ISAnagram("cinema", "iceman")); Assert.IsTrue(ISAnagram("Tom Marvolo Riddle", "I am Lord Voldemort")); Assert.IsTrue(ISAnagram("Dave Barry", "Ray Adverb")); Assert.IsTrue(ISAnagram("debit card", "bad credit")); Assert.IsTrue(ISAnagram("astronomer", "Moon starer")); Assert.IsTrue(ISAnagram("abc123", "c3b2a1")); Assert.IsTrue(!ISAnagram("banana", "bananas")); Assert.IsTrue(!ISAnagram("bananab", "abanana")); Assert.IsTrue(!ISAnagram("Tom Riddle", "I'm Lord Voldemort?")); Assert.IsTrue(!ISAnagram("abc123", "a11b22c33")); } public bool ISAnagram(string v1, string v2) { v1 = v1.Replace(" ", String.Empty); v2 = v2.Replace(" ", String.Empty); if (v1.Length != v2.Length) return false; //Convert string to character array char[] firstCharsArray = v1.ToLower().ToCharArray(); char[] secondCharsArray = v2.ToLower().ToCharArray(); //Sort array Array.Sort(firstCharsArray); Array.Sort(secondCharsArray); //Check each character and position. for (int i = 0; i < firstCharsArray.Length; i++) { if (firstCharsArray[i].ToString().ToLower() != secondCharsArray[i].ToString().ToLower()) { return false; } } return true; } } }
run
|
edit
|
history
|
help
0
Fuuuu
Login Silencioso
Classes, properties, methods, ling begining
ref and out
ReverseArrayC#
HexaStringToFile
ArithmeticOperations
Kumaran-RegText-CityStatePostalCode Parsing
Sort example
фабрика статик