[Locked] Generalized abbreviation

Source: Internet
Author: User

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"]

Analysis:

DFS or BFS, replacing letters with numbers according to rules, paying attention to the correctness of recursive conditions and parameters

Code:

voidDfsstring&AMP;STR, vector<string> &AMP;VR,stringCurintCountinti) {//Condition for ending    if(i = =str.length ()) {        if(Count >0) cur+=Char(Count +'0');        Vr.push_back (cur); return; }    //Stop converting the characters into numbers    if(Count >0) DFS (str, VR, cur+Char(Count +'0') + Str[i],0, i +1); ElseDFS (str, VR, cur+ Str[i],0, i +1); //Continue converting ....DFS (str, VR, cur, Count +1, i +1); return;} Vector<string> vs (stringstr) {Vector<string>Vresults; DFS (str, vresults,"",0,0); returnvresults;}



[Locked] Generalized abbreviation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.