水题,直接按要求做就可以
代码语言:javascript复制class Solution {
public:
string evaluate(string s, vector<vector<string>>& knowledge) {
map<string,string>p;
for(int i=0;i<knowledge.size();i ){
p[knowledge[i][0]]=knowledge[i][1];
}
string ans;
for(int i=0;s[i];i ){
if(s[i]=='('){
int j=i;
string tep;
while(s[j]!=')')j ;
tep=s.substr(i 1,j-i-1);
if(!p.count(tep))tep="?";
else tep=p[tep];
ans =tep;
i=j;
continue;
}
ans =s[i];
}
return ans;
}
};