#include<iostream>#include<list>#include<queue>#include<sstream>using namespace std;class treeNode{public: list<treeNode*> file; string name; int size; int totSize; bool read(); void calcsize(); void print(); static int recurcalc(treeNode* subtree); static void recurprint(treeNode* subtree,vector<bool>& vb,bool isLast);};bool treeNode::read(){ string line; if(getline(cin,line)) { istringstream iss; iss.clear(); iss.str(line); iss >> name >> size; queue<treeNode*> q; if(name[0] == '*') q.push(this); while(!q.empty()) { getline(cin,line); bool inP = false; string contain; for(int i = 0; i < line.size(); ++i) { if(inP == true) { if(line[i] == ')') { iss.clear(); iss.str(contain); contain.clear(); string nm; int sz; treeNode* father = q.front(); q.pop(); while(iss >> nm >> sz) { treeNode* node = new treeNode; node->name = nm; node->size = sz; if(node->name[0] == '*') q.push(node); father->file.push_back(node); } inP = false; } else contain += line[i]; } else if(inP == false && line[i] == '(') inP = true; } } } else return false;}void treeNode::calcsize(){ recurcalc(this);}int treeNode::recurcalc(treeNode* subtree){ subtree->totSize = subtree->size; for(list<treeNode*>::iterator p = subtree->file.begin(); p != subtree->file.end(); ++p) subtree->totSize += recurcalc(*p); return subtree->totSize;}void treeNode::print(){ vector<bool> vb; recurprint(this,vb,false);}void treeNode::recurprint(treeNode* subtree,vector<bool>& vb,bool notLast){ for(int i = 0; i < vb.size(); ++i) { if(vb[i] == false) cout << " "; else cout << "|"; cout << " "; } vb.push_back(notLast); cout << "|_" << subtree->name << "[" << subtree->totSize << "]" << endl; for(list<treeNode*>::iterator p = subtree->file.begin(); p != subtree->file.end(); ++p) { bool tmp; ++p; tmp = !(p == subtree->file.end()); --p; recurprint(*p,vb,tmp); vb.pop_back(); }}int main(){ while(1) { treeNode root; if(!root.read()) break; root.calcsize(); root.print(); } return 0;}