We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You can use a deque to keep track of the token stack and use a deque to string mapping function to resolve it to an attributeDB entry:
stringd_to_string(constdeque<string>&d){strings;for(constauto&t:d){if(t[0]=='<'){if(s.size())s+='.';s+=t.substr(1);}elses+='~'+t;}returns;}[...]cin.ignore();deque<string>tags;[...]if(word[0]=='<'){// tag::end -> popif(word[1]=='/'){tags.pop_back();// tag::begin -> push}else{// the "- (word[word.size()-1] == '>')" trick is needed to pass half the cases// this is due to no-attr tags of the form "<tag>" and "<tag>" being in the deque// instead of "<tag"tags.push_back(word.substr(0,word.size()-(word[word.size()-1]=='>')));}// attr::val}elseif(word[0]=='"'){size_tpos=word.find_last_of('"');attr_db.insert({d_to_string(tags)],word.substr(1,pos-1)});tags.pop_back();// attr::name}elseif(word[0]!='='){tags.push_back(word);}[...]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Attribute Parser
You are viewing a single comment's thread. Return to all comments →
You can use a deque to keep track of the token stack and use a deque to string mapping function to resolve it to an attributeDB entry: