Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int min(int a, int b, int c){
  6. if (a <= b && a <= c){
  7. return a;
  8. }
  9. if (b <= a && b <= c){
  10. return b;
  11. }
  12. if (c <= a && c <= b){
  13. return c;
  14. }
  15. }
  16.  
  17. int main() {
  18. char string_1[1001];
  19. char string_2[1001];
  20. cin >> string_1 >> string_2;
  21. int length_1 = strlen(string_1), length_2 = strlen(string_2);
  22. int** arr = new int*[length_1 + 1];
  23. for (int i = 0; i <= length_1; ++i){
  24. arr[i] = new int[length_2 + 1];
  25. }
  26. for (int i = 0; i <= length_1; ++i){
  27. for (int j = 0; j <= length_2; ++j){
  28. if(i == 0 && j == 0){
  29. arr[i][j] = 0;
  30. continue;
  31. }
  32. if (j == 0 && i != 0){
  33. arr[i][j] = i;
  34. continue;
  35. }
  36. if (i == 0 && j != 0){
  37. arr[i][j] = j;
  38. continue;
  39. }
  40. if (string_1[i - 1] == string_2[j - 1]){
  41. arr[i][j] = arr[i - 1][j - 1];
  42. continue;
  43. }
  44. arr[i][j] = min(arr[i][j - 1] + 1, arr[i - 1][j] + 1, arr[i - 1][j - 1] + 1);
  45. }
  46. }
  47. /*
  48. for (int i = 0; i <= length_1; ++i){
  49. for (int j = 0; j <= length_2; ++j){
  50. cout << arr[i][j] << " ";
  51. if (j == length_2)
  52. cout << "\n";
  53. }
  54. }
  55. */
  56. cout << arr[length_1][length_2] << "\n";
  57. /*
  58. cout << length_1 << "\n" << length_2;
  59. */
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement