Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //206
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <math.h>
- #include <string>
- #include <algorithm>
- #include <climits>
- #include <vector>
- using namespace std;
- int levis(string s1, string s2)
- {
- int n = s1.length(), m = s2.length();
- if (m == 0)
- return n;
- if (n == 0)
- return m;
- vector<vector<int> > d(n + 1, vector<int>(m + 1));
- for (int i = 0; i <= n; i++)
- d[i][0] = i;
- for (int j = 0; j <= m; j++)
- d[0][j] = j;
- int c = 0, a;
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- if (s1[i - 1] == s2[j - 1])
- c = 0;
- else
- c = 1;
- a = min(d[i - 1][j] + 1, d[i][j - 1] + 1);
- d[i][j] = min(a, d[i - 1][j - 1] + c);
- }
- }
- return d[n][m];
- }
- double gakkar(string s1, string s2)
- {
- double c = 0;
- if (s1.length() <= s2.length())
- {
- for (int i = 0; i < s1.length(); i++) {
- if (s1[i] == s2[i])
- c++;
- }
- }
- else
- {
- for (int i = 0; i < s2.length(); i++)
- if (s1[i] == s2[i])
- c++;
- }
- c = c / (s1.length() + s2.length() - c);
- return c;
- };
- string norm2(string s)
- {
- string x, k;
- int i = 0;
- while ((int)s[i] == 32)
- i++;
- for (; i<s.length(); i++)
- {
- if ((int)s[i] == 32)
- if (k.length() > 3)
- {
- x = x + k + " ";
- k = "";
- }
- else
- k = "";
- else
- k = k + s[i];
- }
- if (k.length() > 3)
- x = x + k;
- return x;
- }
- string norm3(string s)
- {
- int i = s.length() - 1;
- while (s[i] == 32)
- i--;
- s = s.substr(0, i);
- return s;
- }
- string norm1(string s)
- {
- string x;
- for (int i = 0; i < s.length(); i++)
- {
- int a = (int)s[i];
- if ((a == 32) || ((a >= 48) && (a <= 57)) || ((a >= 97) && (a <= 122)))
- x = x + s[i];
- if ((a >= 65) && (a <= 90))
- {
- s[i] += 32;
- x = x + s[i];
- }
- }
- return x;
- };
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- string s1,s2, m;
- getline(cin, s1);
- getline(cin, s2);
- s1 = norm1(s1);
- s1 = norm2(s1);
- s2 = norm1(s2);
- s2 = norm2(s2);
- //s1 = norm3(s1);
- //s2 = norm3(s2);
- cout.precision(8);
- cout << levis(s1, s2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement