Helper.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. namespace SchoolProject
  8. {
  9. public class Helper
  10. {
  11. public static void ErrorMessage(string TextMessagre)
  12. {
  13. MessageBox.Show(TextMessagre, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
  14. }
  15. public static void InformationMessage(string TextMessagre)
  16. {
  17. MessageBox.Show(TextMessagre, "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
  18. }
  19. public static int LevenshteinDistance(string string1, string string2)
  20. {
  21. if (string1 == null) throw new ArgumentNullException("string1");
  22. if (string2 == null) throw new ArgumentNullException("string2");
  23. int diff;
  24. int[,] m = new int[string1.Length + 1, string2.Length + 1];
  25. for (int i = 0; i <= string1.Length; i++) { m[i, 0] = i; }
  26. for (int j = 0; j <= string2.Length; j++) { m[0, j] = j; }
  27. for (int i = 1; i <= string1.Length; i++)
  28. {
  29. for (int j = 1; j <= string2.Length; j++)
  30. {
  31. diff = (string1[i - 1] == string2[j - 1]) ? 0 : 1;
  32. m[i, j] = Math.Min(Math.Min(m[i - 1, j] + 1,
  33. m[i, j - 1] + 1),
  34. m[i - 1, j - 1] + diff);
  35. }
  36. }
  37. return m[string1.Length, string2.Length];
  38. }
  39. }
  40. }