[C++] 查找所有公共子串_lcs_vt →→→→→进入此内容的聊天室

来自 , 2020-11-28, 写在 C++, 查看 135 次.
URL http://www.code666.cn/view/44968aec
  1. const vector<string> lcs_vt(const string &str1, const string &str2)
  2. {
  3.     int col_num = str1.length();
  4.     int row_num = str2.length();
  5.     int map[row_num][col_num];
  6.  
  7.     bzero(map, sizeof(map));
  8.     vector<string> ret;
  9.  
  10.     for(int i = 0; i < col_num; i++) {
  11.         for(int j = 0; j < row_num; j++) {
  12.             if (str1[i] == str2[j]) {
  13.                 map[j][i] = 1;
  14.             }
  15.         }
  16.     }
  17.  
  18.     int list_flag = 0;
  19.     string temp;
  20.     for (int i = col_num - 1; i >= 0; i--) {
  21.         int j = 0;
  22.         temp = "";
  23.         while(j + i < col_num && j < row_num) {
  24.             if (map[j][j + i] == 1) {
  25.                 temp += str1[j + i];
  26.             } else {
  27.                 temp += '#';
  28.             }
  29.             j++;
  30.         }
  31.         vector<string> splited_str = split_with_string(temp, "#");
  32.         vector_unique(splited_str);
  33.         for(unsigned int i = 0; i < splited_str.size(); i++) {
  34.             ret.push_back(splited_str[i]);
  35.         }
  36.     }
  37.  
  38.     for (int i = 1; i < row_num; i++) {
  39.         int j = 0;
  40.         temp = "";
  41.         while(j < col_num && j + i < row_num) {
  42.             if (map[j + i][j] == 1) {
  43.                 temp += str2[j + i];
  44.             } else {
  45.                 temp += '#';
  46.             }
  47.             j++;
  48.         }
  49.         //if (!(temp.empty())) {
  50.         //  cout << "###" << temp << endl;
  51.         //}
  52.         vector<string> splited_str = split_with_string(temp, "#");
  53.         vector_unique(splited_str);
  54.         for(unsigned int i = 0; i < splited_str.size(); i++) {
  55.             ret.push_back(splited_str[i]);
  56.         }
  57.     }
  58.     return ret;
  59. }
  60.  

回复 "查找所有公共子串_lcs_vt"

这儿你可以回复上面这条便签

captcha