http://codeforces.com/problemset/problem/51/B
利用stack类似与括号匹配,每个 <table>ROWS</table> 划分一个模块,
一个 <td>TABLE</td>记录多少个CELL, stack中存的是模块的序号。
View Code
const int MM = 511111; const double esp=1e-8; const double lep=0.0000001; #define maxint 0x3f3f3f3f typedef __int64 int64; #define debug puts("wrong") #define clr(a) memset(a,0,sizeof(a)) char str[111][5555]; int N; int num[55555],cnt; int st[55555], top; string ch; int get_id(char s,int op,int &i) { if(s=='a') {i+=4;return op*1;} else if(s=='d') {i+=1;return op*2;} else {i+=1;return op*3;} } void get_data() { int i,j,k,len; N=0; while(scanf("%s",str[N])!=EOF) { if(str[N][0]=='#') break; N++; } ch=""; for(i=0;i<N;i++) { for(j=0;str[i][j];j++) ch+=str[i][j]; } // cout<<ch<<endl; for(i=cnt=0;i<ch.length();i++) { if(ch[i]=='<') { if(ch[i+1]=='t') { i+=2; num[cnt++]=get_id(ch[i],1,i); } else { i+=3; num[cnt++]=get_id(ch[i],-1,i); } } } } //ta->1 tr->3 td->2 void solve() { int i,j,k,ans[55555],mm=0,tmp=0,now=0; top=0; memset(ans,0,sizeof(ans)); for(i=0;i<cnt;i++) { if(num[i]>0) { if(num[i]==1) st[top++]=now++; else if(num[i]==2) ans[st[top-1]]++; } else if(num[i]==-1) top--; } sort(ans,ans+now); for(i=0;i<now;i++) printf("%d ",ans[i]); printf("\n"); } int main() { get_data(),solve(); return 0; }