반응형
https://www.hackerrank.com/challenges/attribute-parser
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map<string, string> tagMap;
void createTag(int& n,string pretag)
{
if(!n) return;
string line,tag,attr,value;
getline(cin,line);
int i=1;
if(line[i]=='/'){
while(line[i]!='>')i++;
if(pretag.size()>(i-2))
tag=pretag.substr(0,pretag.size()-i+1);
else
tag="";
}
else{
while(line[i]!=' '&&line[i]!='>')i++;
tag=line.substr(1,i-1);
if(pretag!="")
tag=pretag+"."+tag;
int j;
while(line[i]!= '>'){
j=++i;
while(line[i]!=' ') i++;
attr=line.substr(j,i-j);
while(line[i]!='"') i++;
j=++i;
while(line[i]!='"')i++;
value=line.substr(j,i-j);
++i;
tagMap[tag+'~'+attr]=value;
}
}
createTag(--n,tag);
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int numofLine,query;
cin>>numofLine>>query;
cin.ignore();
createTag(numofLine,"");
string attr,value;
while(query--){
getline(cin,attr);
value=tagMap[attr];
if(value=="") cout<<"Not Found!";
cout<<value<<endl;
}
return 0;
}
반응형
'C++' 카테고리의 다른 글
[HackerRank] Strings - Easy (0) | 2019.10.14 |
---|---|
[HackerRank] StringStream - Easy (0) | 2019.10.14 |
[HackerRank] Variable Sized Arrays - Easy (0) | 2019.10.13 |
[HackerRank] Array Introduction - Easy (0) | 2019.10.12 |
[HackerRank] Pointer - Easy (0) | 2019.10.12 |
댓글