Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. //206
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <math.h>
  5. #include <string>
  6. #include <algorithm>
  7. #include <climits>
  8. #include <vector>
  9. using namespace std;
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. int levis(string s1, string s2)
  18. {
  19.     int n = s1.length(), m = s2.length();
  20.  
  21.     if (m == 0)
  22.         return n;
  23.     if (n == 0)
  24.         return m;
  25.  
  26.     vector<vector<int> > d(n + 1, vector<int>(m + 1));
  27.  
  28.     for (int i = 0; i <= n; i++)
  29.         d[i][0] = i;
  30.     for (int j = 0; j <= m; j++)
  31.         d[0][j] = j;
  32.  
  33.     int c = 0, a;
  34.  
  35.     for (int i = 1; i <= n; i++)
  36.     {
  37.         for (int j = 1; j <= m; j++)
  38.         {
  39.             if (s1[i - 1] == s2[j - 1])
  40.                 c = 0;
  41.             else
  42.                 c = 1;
  43.             a = min(d[i - 1][j] + 1, d[i][j - 1] + 1);
  44.             d[i][j] = min(a, d[i - 1][j - 1] + c);
  45.         }
  46.     }
  47.     return d[n][m];
  48. }
  49.  
  50. double gakkar(string s1, string s2)
  51. {
  52.     double c = 0;
  53.     if (s1.length() <= s2.length())
  54.     {
  55.         for (int i = 0; i < s1.length(); i++) {
  56.             if (s1[i] == s2[i])
  57.                 c++;
  58.         }
  59.     }
  60.     else
  61.     {
  62.         for (int i = 0; i < s2.length(); i++)
  63.             if (s1[i] == s2[i])
  64.                 c++;
  65.     }
  66.     c = c / (s1.length() + s2.length() - c);
  67.  
  68.  
  69.     return c;
  70.        
  71.  
  72.  
  73. };
  74.  
  75. string norm2(string s)
  76. {
  77.     string x, k;
  78.     int i = 0;
  79.  
  80.     while ((int)s[i] == 32)
  81.         i++;
  82.  
  83.     for (; i<s.length(); i++)
  84.     {
  85.         if ((int)s[i] == 32)
  86.             if (k.length() > 3)
  87.             {
  88.                 x = x + k + " ";
  89.                 k = "";
  90.             }
  91.             else
  92.                 k = "";
  93.         else
  94.             k = k + s[i];
  95.     }
  96.     if (k.length() > 3)
  97.         x = x + k;
  98.     return x;
  99. }
  100.  
  101. string norm3(string s)
  102. {
  103.     int i = s.length() - 1;
  104.     while (s[i] == 32)
  105.         i--;
  106.     s = s.substr(0, i);
  107.     return s;
  108. }
  109.  
  110. string norm1(string s)
  111. {
  112.     string x;
  113.     for (int i = 0; i < s.length(); i++)
  114.     {
  115.         int a = (int)s[i];
  116.         if ((a == 32) || ((a >= 48) && (a <= 57)) || ((a >= 97) && (a <= 122)))
  117.             x = x + s[i];
  118.         if ((a >= 65) && (a <= 90))
  119.         {
  120.             s[i] += 32;
  121.             x = x + s[i];
  122.         }
  123.     }
  124.     return x;
  125. };
  126.  
  127.  
  128. int main()
  129. {
  130.     freopen("input.txt", "r", stdin);
  131.     freopen("output.txt", "w", stdout);
  132.     string s1,s2, m;
  133.  
  134.     getline(cin, s1);
  135.     getline(cin, s2);
  136.  
  137.     s1 = norm1(s1);
  138.     s1 = norm2(s1);
  139.     s2 = norm1(s2);
  140.     s2 = norm2(s2);
  141.     //s1 = norm3(s1);
  142.     //s2 = norm3(s2);
  143.    
  144.     cout.precision(8);
  145.  
  146.     cout <<  levis(s1, s2);
  147.  
  148.  
  149.  
  150.     return 0;
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement