LEETCODE - 1181 before and after splicing []

class Solution {
public:
    string gethead(string str){//获取头单词
        string ret = "";
        int strlen = str.length();
        for(int i = 0; i < strlen; ++i){
            if(str[i] == ' '){
                break;
            }
            entitled + = str [i];
        }
        Return the right;
    }
    string gettail(string str){//获取尾单词
        int strlen = str.length();
        int index = 0;
        for(int i = strlen - 1; i >= 0; i--){
            if(str[i] == ' '){
                index = i;
                break;
            }
        }
        if(index == 0){
            return str;
        }
        return str.substr(index+1,strlen);;
    }
    String deletesubstr ( String str, String substr) { // remove duplicate word for splicing []; you can only delete the first word, you can not delete the last word with a space [about] 
        String strt = str;
         int POS = strT.find (substr);
         IF (POS> - . 1 )
        {
            strT.erase(pos,substr.size());
        }
        return strT;
    }
    vector<string> beforeAndAfterPuzzles(vector<string>& phrases) {
        int phraseslen = phrases.size();
        vector<string> head;
        Vector < String > tail;
         for ( int I = 0 ; I <phraseslen; I ++) { // Get an array of head and tail of the word 
            head.push_back (gethead (phrases [i] ));
            tail.push_back(gettail(phrases[i]));
        }
        Vector < String > RET;
         for ( int J = 0 ; J <phraseslen; J ++) { // tail 
            for ( int K = 0 ; K <phraseslen; ++ K) {
                 IF (J = K && tail [! J] == head [K]) { // If a substring of the other end of the first sub-string is equal 
                    ret.push_back (Phrases [J] + deletesubstr (Phrases [K], head [K])); // he returned to the vessel in stitching together 
                    COUT << Phrases [J] + deletesubstr (Phrases [K], head [K]) << endl;
                }
            }
        }
        black (ret.begin () ret.end ());
        ret.erase (Unique (ret.begin (), ret.end ()), ret.end ()); // 去重
        return right;
    }
};

Guess you like

Origin www.cnblogs.com/wangqiwen-jer/p/12141946.html