/* 题目: XML有缩进,并且会在之前的缩进基础上缩进几个空格,现在问缩进k个空格的标签 分析: 模拟队列,及时更新空格即可 */ #include <iostream> #include <cstdio> #include <cstring> #include <vector> using namespace std; const int X = 20005; int n,k; char s[105]; char p[105]; vector<int> vec[X]; struct node { char s[105]; int num; }q[X],ans[X]; int top,ret; void check() { if(s[0]!='<') return; if(s[1]=='/') { top--; return; } else { int temp = 0; int cnt = 0; bool ok = false;; for(int i=1;s[i];i++) { if(ok) { if(s[i]=='>') break; temp = temp*10+s[i]-'0'; } else if(s[i]!=',') p[cnt++] = s[i]; if(s[i]==',') { p[cnt] = '\0'; ok = true; } } if(top) q[top].num = q[top-1].num+temp; else q[top].num = temp; strcpy(q[top].s,p); strcpy(ans[ret].s,p); ans[ret].num = q[top].num; vec[ans[ret].num].push_back(ret); ret++; top++; } } int main() { freopen("sum.in","r",stdin); while(scanf("%d%d ",&n,&k)!=EOF) { for(int i=0;i<n;i++) vec[i].clear(); top = 0; ret = 0; for(int i=0;i<n;i++) { gets(s); check(); } int len = vec[k].size(); int x; cout<<len<<endl; for(int i=0;i<len;i++) { x = vec[k][i]; printf("%s\n",ans[x].s); } } return 0; }