// @BAKE g++ $@ #include #include #include using namespace std; // https://github.com/Meteorix/pylcs vector utf8_split(const string &str){ vector split; int len = str.length(); int left = 0; int right = 1; for (int i = 0; i < len; i++){ if (right >= len || ((str[right] & 0xc0) != 0x80)){ string s = str.substr(left, right - left); split.push_back(s); // printf("%s %d %d\n", s.c_str(), left, right); left = right; } right ++; } return split; } // https://github.com/schiffma/distlib int mini(int a, int b, int c){ return(min(a, min(b,c))); } int levenshtein_dist(const string &word1, const string &word2){ /// /// Please use lower-case strings /// word1 : first word /// word2 : second word /// //int size1 = word1.size(), size2 = word2.size(); vector word1_ = utf8_split(word1); vector word2_ = utf8_split(word2); int size1 = word1_.size(); int size2 = word2_.size(); int suppr_dist, insert_dist, subs_dist; int* dist = new int[(size1+1)*(size2+1)]; for(int i=0; i