12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace SchoolProject
- {
- public class Helper
- {
- public static void ErrorMessage(string TextMessagre)
- {
- MessageBox.Show(TextMessagre, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- public static void InformationMessage(string TextMessagre)
- {
- MessageBox.Show(TextMessagre, "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- public static int LevenshteinDistance(string string1, string string2)
- {
- if (string1 == null) throw new ArgumentNullException("string1");
- if (string2 == null) throw new ArgumentNullException("string2");
- int diff;
- int[,] m = new int[string1.Length + 1, string2.Length + 1];
- for (int i = 0; i <= string1.Length; i++) { m[i, 0] = i; }
- for (int j = 0; j <= string2.Length; j++) { m[0, j] = j; }
- for (int i = 1; i <= string1.Length; i++)
- {
- for (int j = 1; j <= string2.Length; j++)
- {
- diff = (string1[i - 1] == string2[j - 1]) ? 0 : 1;
- m[i, j] = Math.Min(Math.Min(m[i - 1, j] + 1,
- m[i, j - 1] + 1),
- m[i - 1, j - 1] + diff);
- }
- }
- return m[string1.Length, string2.Length];
- }
- }
- }
|