当前位置:网站首页>Design goal parser. Parse simple topic

Design goal parser. Parse simple topic

2020-12-08 08:14:31 osc_ 9na1lmr9

 

Because the title ensures that the string can be parsed , So according to the index Traversal analysis is enough , utilize C++ substring Skill overall judgment .

class Solution {
public:
    string interpret(string command) {
        string res;
        for(int i=0;i<command.size();i++){
            if(command[i]=='G'){
                res+='G';
            }else if(command.substr(i,4)=="(al)"){
                res+="al";
                i+=3;
            }else{
                res+="o";
                i+=1;
            }
        }
        return res;
    }
};

 

版权声明
本文为[osc_ 9na1lmr9]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201208080404601i.html