Input The first line of the input is an integer T representing the number of test cases.
Each test case is a valid HTML document starts with a tag and ends with a tag. See sample below for clarification of the input format.
The size of the input file will not exceed 20KB.
Output For each test case, first output a line “Case #x:”, where x is the case number (starting from 1).
Then you should write to the output the formatted parse trees as described above. See sample below for clarification of the output format.
Sample Input
2ACM ICPC
Hello
WorldAsia Chengdu Regional
ACM-ICPC
Sample Output
[pre]Case #1:ACM ICPC
Hello
WorldCase #2:Asia Chengdu Regional
ACM-ICPC
[/pre] Hint Please be careful of the number of leading spaces of each line in above sample output.
Source 2013 Asia Chengdu Regional Contest
思路:注意以下几点:①\n \t 都要当成空格处理。② ③行末空格。 ④<里面的东西不能动>
#include#include char s[50000]; int nxt[50000]; void ps(int x)//输出前面的空格 { puts(""); for(int i=0;i 里面 scanf("%d",&T); len=0; while(gets(s+len)!=NULL)//先全部读入 { if(!s[0]) continue; len=strlen(s); s[len]=' ';//末尾加个空格 len++; } in=0; for(i=0;i ') in=0; else if(!in && s[i]=='\t') s[i]=' ';//把制表符换成空格,方便后面处理 nxt[i]=i+1; } last=0; in=0; for(i=1;i ') in=0; if(s[i]==' ') { if((!in && s[last]==' ') || s[last]=='>') nxt[last]=nxt[i];//过滤掉多余的空格 else last=i; } else last=i; } // for(i=head;i ')//特判 { if(suojin) ps(suojin); printf(""); i=nxt[nxt[nxt[i]]]; } else if(s[i]=='<' && s[i+1]!='/') { if(suojin) ps(suojin); for(j=i;j ') break; else if(s[j]=='/' && s[j+1]=='>') suojin--;//
} i=nxt[j]; suojin++; } else if(s[i]=='<' && s[i+1]=='/') { suojin--; ps(suojin); for(j=i;j') break; } i=nxt[j]; if(suojin==0) { if(cas>T) { puts(""); return 0; } printf("\nCase #%d:\n",cas++); } } else { ps(suojin); for(j=i;j