Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include<math.h>
  3. #include<vector>
  4. #include <queue>
  5. #include <stack>
  6. #include<string>
  7. #include <iomanip>
  8. #include <algorithm>
  9. #include <climits>
  10. using namespace std;
  11.  
  12. string s, ss;
  13.  
  14. string clean(string s)
  15. {
  16. int i = 0, counter = 0;
  17. string a;
  18. for (int i = 0; i < s.length(); i++)
  19. {
  20. if (s[i] == 32 || (s[i] >= 97 && s[i] <= 122) || (s[i] >= 48 && s[i] <= 57))
  21. a += s[i];
  22. else if (s[i] >= 65 && s[i] <= 90)
  23. a += tolower(s[i]);
  24. }
  25. int len = a.length();
  26. while (i < len)
  27. {
  28. if (a[i] != char(32))
  29. {
  30. counter++;
  31. i++;
  32. }
  33. else
  34. {
  35. if (counter <= 3)
  36. {
  37. a.erase(i - counter, counter + 1);
  38. len = a.length();
  39. i = i - counter;
  40. counter = 0;
  41. }
  42. else
  43. {
  44. i++;
  45. counter = 0;
  46. }
  47. }
  48. }
  49. if (counter <= 3)
  50. a.erase(i - counter, counter + 1);
  51. counter = 0;
  52. return a;
  53. }
  54.  
  55. int algo(string s, string ss)
  56. {
  57. int n = s.length(), m = ss.length();
  58.  
  59. if (m == 0)
  60. return n;
  61. if (n == 0)
  62. return m;
  63.  
  64. vector<vector<int> > d(n+1, vector<int>(m+1));
  65.  
  66. for (int i = 0; i <= n; i++)
  67. d[i][0] = i;
  68. for (int i = 0; i <= m; i++)
  69. d[0][i] = i;
  70.  
  71. int counter = 0, temp;
  72.  
  73. for (int i = 1; i <= n; i++)
  74. {
  75. for (int j = 1; j <= m; j++)
  76. {
  77. if (s[i - 1] == ss[j - 1])
  78. counter = 0;
  79. else
  80. counter = 1;
  81. temp = min(d[i - 1][j] + 1, d[i][j - 1] + 1);
  82. d[i][j] = min(temp, d[i - 1][j - 1] + counter);
  83. }
  84. }
  85. return d[n][m];
  86. }
  87.  
  88.  
  89. int main()
  90. {
  91. freopen("input.txt", "r", stdin);
  92. freopen("output.txt", "w", stdout);
  93.  
  94. double counter = 0, q, q1;
  95. double answer;
  96. getline(cin, s);
  97. q = s.length();
  98. s = clean(s);
  99. getline(cin, ss);
  100. q1 = ss.length();
  101. ss = clean(ss);
  102.  
  103. cout<< algo(s, ss);
  104. }//Π»ΠΈΠ²
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement