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.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>#include<sstream>usingnamespacestd;classTags{vector<string>attributes,values;intattIndex(string&att){for(inti=0;i<attributes.size();i++){if(attributes[i]==att){returni;}}return-1;}public:voidpushValues(string&att,string&val){attributes.push_back(att);values.push_back(val);}voidprintQuery(string&att){intindex=attIndex(att);if(index==-1){cout<<"Not Found"<<'\n';}else{cout<<values[index]<<'\n';}}};classHRML{vector<Tags>ts;intn,q;public:voidsetTags(){intequals=0;Tagst;charc;stringinput,atts,vals;stringstreamss;stringtemp;cin>>n>>q;ts.resize(n);// Consume the newline character after reading n and qcin.ignore();for(inti=0;i<n/2;i++){getline(cin,input);ss.clear();ss.str(input);ss>>temp;while(ss>>temp){if(temp=="="&&equals==0){equals=1;continue;}elseif(equals==1){vals=temp;ts[i].pushValues(atts,vals);equals=0;}elseif(equals==0){atts=temp;}}}for(inti=0;i<n/2;i++){cin>>temp;};}voidprintQueries(){stringstreamss1;inttagno=0;stringinput,temp,tagName;for(inti=0;i<q;i++){getline(cin,input,'~');ss1.clear();ss1.str(input);getline(cin,tagName);tagno=0;while(ss1>>temp){tagno++;}// Check if tagno is within boundsif(tagno>0&&tagno<=n){ts[tagno-1].printQuery(tagName);// Adjusted index}else{cout<<"Not Found"<<'\n';}}}};intmain(){HRMLa;a.setTags();a.printQueries();return0;}
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 →
can anyone help me with the code??