Attribute Parser

Sort by

recency

|

478 Discussions

|

  • + 0 comments

    include

    include

    include

    include

    include

    using namespace std;

    int main() { int n, q; cin >> n >> q; cin.ignore();

    map<string, string> attributes;
    string line, tag_path = "";
    
    for (int i = 0; i < n; ++i) {
        getline(cin, line);
        // Remove '<' and '>'
        line.erase(remove(line.begin(), line.end(), '>'), line.end());
        line.erase(remove(line.begin(), line.end(), '<'), line.end());
    
        stringstream ss(line);
        string word;
        ss >> word;
    
        if (word[0] == '/') {
            // Closing tag
            size_t pos = tag_path.rfind('.');
            if (pos != string::npos) {
                tag_path = tag_path.substr(0, pos);
            } else {
                tag_path = "";
            }
        } else {
            // Opening tag
            string tag_name = word;
            if (!tag_path.empty()) {
                tag_path += "." + tag_name;
            } else {
                tag_path = tag_name;
            }
    
            // Parse attributes
            string attr_name, eq, attr_value;
            while (ss >> attr_name >> eq >> attr_value) {
                // Remove quotes from attr_value
                attr_value = attr_value.substr(1, attr_value.length() - 2);
                string key = tag_path + "~" + attr_name;
                attributes[key] = attr_value;
            }
        }
    }
    
    for (int i = 0; i < q; ++i) {
        string query;
        getline(cin, query);
        if (attributes.find(query) != attributes.end()) {
            cout << attributes[query] << endl;
        } else {
            cout << "Not Found!" << endl;
        }
    }
    
    return 0;
    

    }

  • + 0 comments

    Here is Attribute Parser solution in c++ - https://programmingoneonone.com/hackerrank-attribute-parser-solution-in-cpp.html

  • + 0 comments

    20th Century Boys Manga , Read the latest Chapters of 20th Century Boys Manga Online free in English With High Quality. at 20thcenturyboys.club.

  • + 0 comments

    Monster (Japanese: モンスター Hepburn: Monsutā, sometimes referred to as “Naoki Urasawa's Monster”) is a Japanese manga series written by Naoki. Monster Manga Online

  • + 0 comments

    The problem said NOTHING about how to handle duplicate attribute names. Stupid hacker rank prompts suck. You're supposed to fail if they reuse an attribute name FYI.