Changeset 7240 for code/branches/consolecommands3/src/libraries
- Timestamp:
- Aug 28, 2010, 6:58:30 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/util/StringUtils.cc
r7238 r7240 538 538 size_t cols = str1.size() + 1; 539 539 size_t rows = str2.size() + 1; 540 int matrix[rows][cols];540 int* matrix = new int[rows * cols]; 541 541 542 542 for (size_t r = 0; r < rows; ++r) 543 543 for (size_t c = 0; c < cols; ++c) 544 matrix[r ][c] = 0;544 matrix[r*cols + c] = 0; 545 545 546 546 for (size_t i = 1; i < cols; ++i) 547 matrix[0 ][i] = i;547 matrix[0*cols + i] = i; 548 548 for (size_t i = 1; i < rows; ++i) 549 matrix[i ][0] = i;549 matrix[i*cols + 0] = i; 550 550 551 551 for (size_t r = 1; r < rows; ++r) 552 552 for (size_t c = 1; c < cols; ++c) 553 matrix[r ][c] = (str1[c-1] != str2[r-1]);553 matrix[r*cols + c] = (str1[c-1] != str2[r-1]); 554 554 555 555 for (size_t r = 1; r < rows; ++r) 556 556 for (size_t c = 1; c < cols; ++c) 557 matrix[r][c] = std::min(std::min(matrix[r-1][c] + 1, matrix[r][c-1] + 1), matrix[r-1][c-1] + (str1[c-1] != str2[r-1])); 558 559 return matrix[rows-1][cols-1]; 557 matrix[r*cols + c] = std::min(std::min(matrix[(r-1)*cols + c] + 1, 558 matrix[r*cols + c-1] + 1), 559 matrix[(r-1)*cols + c-1] + (str1[c-1] != str2[r-1])); 560 561 int result = matrix[(rows-1)*cols + cols-1]; 562 delete[] matrix; 563 return result; 560 564 } 561 565 }
Note: See TracChangeset
for help on using the changeset viewer.