You are viewing a single comment's thread. Return to all comments →
Easy C++ Metgod ::
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <sstream> #include <numeric> #include <string> using namespace std; std::vector<std::string> split(const std::string &s, char delim) { std::vector<std::string> tokens; std::stringstream ss(s); std::string token; while (std::getline(ss, token, delim)) { tokens.push_back(token); } return tokens; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n,q; cin>>n>>q; vector<string> words; vector<string> headers; for(int i=0;i<=n;i++){ string temp; getline(cin,temp); if(temp!=""){ //string q = temp.substr(1,temp.length()-2); stringstream ss(temp); string word; vector<string> values; while (ss >> word) { //cout<<word<<" "; if(word[0]=='<' && word[1]!='/'){ string x = word.substr(1,word.length()-1); if(x[x.length()-1]=='>') x = word.substr(1,word.length()-2); //cout<<"Header : "+x<<endl; headers.push_back(x); } else{ values.push_back(word); if(word[1]!='/' && word[word.length()-1]=='>'){ string tvalue = ""; for (const auto& w : values) { tvalue = tvalue+w; if(w[w.length()-1]=='"') tvalue+='#'; } values.clear(); string header = ""; header = std::accumulate(headers.begin(), headers.end(), std::string(), [](const std::string &a, const std::string &b) { return a + "." + b; }); vector<string> vparts = split(tvalue,'#'); header.erase(0,1); for(const auto& v:vparts){ string fi = header+'~'+v.substr(0,v.length()-1); if(fi[fi.length()-1]!='"') fi+='"'; words.push_back(fi); //cout<<fi<<endl; } //cout<<value<<endl; } if(word[1]=='/' && !headers.empty()){ headers.pop_back(); } } } } } /*for (const auto& w : words) { std::cout << w << std::endl; }*/ for(int i=0;i<q;i++){ //cout<<"query= "; string temp; getline(cin,temp); if(temp != ""){ //cout<<temp<<endl; bool found =false; for(const auto& w:words){ vector<string> parts = split(w, '='); if(parts.at(0)==temp){ found =true; cout<<parts.at(1).substr(1,parts.at(1).length()-2)<<endl; break; } } if (!found) { cout<<"Not Found!"<<endl; } } } //cout<<str; return 0; }
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 →
Easy C++ Metgod ::