设为首页 加入收藏

TOP

HDU-4782-Beautiful Soup(模拟)(二)
2015-07-20 17:32:31 来源: 作者: 【 】 浏览:6
Tags:HDU-4782-Beautiful Soup 模拟
thout white spaces) are separated by single space. There should not be any trailing space after each line nor any blank line in the output. The line contains only white spaces is also considered as blank line. You quickly realize that your only job is to deal with the white spaces.
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
2

ACM ICPC

Hello
World

Asia Chengdu Regional

ACM-ICPC


Sample Output
[pre]Case #1:

 
  

ACM ICPC

Hello
World

Case #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

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇整合了刷新、加载更多、滑动删除.. 下一篇hdu 1180 诡异的楼梯 (bfs)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)