[Locked] Generalized Abbreviation

Write a function to generate the generalized abbreviations of a word.

Example:
Given word = "word", return the following list (order does not matter):

["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d","w3", "4"]

分析:

  DFS或者BFS,按照规则将字母替换成数字,注意递归条件和参数的正确性

代码:

void dfs(string &str, vector<string> &vr, string cur, int count, int i) {
//Condition for ending
if(i == str.length()) {
if(count > )
cur += char(count + '');
vr.push_back(cur);
return;
}
//Stop converting the characters into numbers
if(count > )
dfs(str, vr, cur + char(count + '') + str[i], , i + );
else
dfs(str, vr, cur + str[i], , i + );
//Continue converting ....
dfs(str, vr, cur, count + , i + );
return;
}
vector<string> vs(string str) {
vector<string> vResults;
dfs(str, vResults, "", , );
return vResults;
}


上一篇:使用代码生成工具快速生成基于ABP框架的Vue+Element的前端界面


下一篇:利用代码生成工具生成基于ABP框架的代码