HDU 4782 Beautiful Soup
来源:互联网 发布:网络诈骗的小品剧本 编辑:程序博客网 时间:2024/05/16 03:59
2013成都区域赛题目
题意:
就是把HTML代码格式化。
1.每段文本里的单词只能以空格分割,多余的换行符,空格,tab什么的都要去掉。
2.标签不用管,原样输出。
3.这题可能一行内输入多组"<html></html>"
code:
#include <algorithm>#include <iostream>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <string>#include <math.h>#include <vector>#include <queue>#include <stack>#include <cmath>#include <list>#include <set>#include <map>using namespace std;#define N 100010#define ll long long#define ALL(x) x.begin(),x.end()#define CLR(x,a) memset(x,a,sizeof(x))#define bit(st,i) ((1ll<<i)&st)typedef pair<int,int> PI;const int INF=0x3fffffff;const int MOD =1000003;const double EPS=1e-7;string s,txt,input;char buf[N];const char delim[3]={32,9,10};bool isOpen(int i,int t){ return s[i+1]!='/' && s[t-1]!='/';}bool isClose(int i){ return s[i+1]=='/';}void printTxt(int top){ char *p=strtok(&txt[0],delim); if(p==NULL) return ; printf("%s%s",string(top,' ').c_str(),p); p=strtok(NULL,delim); while(p!=NULL){ printf(" %s",p); p=strtok(NULL,delim); } puts("");}void format(){ int dep=-1; txt.clear(); for(int i=0;i<s.size();i++){ if(s[i]=='<'){ if(txt.size()>0){ printTxt(dep+1); txt.clear(); } int t=i,top; while(s[t]!='>') t++; if(isOpen(i,t)) top=++dep; else if(isClose(i)) top=dep--; else top=dep+1; printf("%s%s\n",string(top,' ').c_str(),s.substr(i,t-i+1).c_str()); i=t; }else txt+=s[i]; }}int main(){ //freopen("output.txt","w",stdout); int re,Case=1,begin=0,end; scanf("%d",&re); while(gets(buf)) input+=" ", input+=buf; for(int i=1;i<=re;i++){ end=input.find("</html>",begin)+6; s=input.substr(begin,end-begin+1); printf("Case #%d:\n",Case++); format(); begin=end+1; } return 0;}
0 0
- HDU 4782 Beautiful Soup
- HDU 4782 Beautiful Soup 模拟
- HDU 4782 Beautiful Soup 模拟
- HDU-4782-Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup --模拟
- hdu - 4782 - Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup(模拟)
- hdu 4782 Beautiful Soup(模拟)
- 2013成都国赛 hdu 4782 Beautiful Soup (模拟)
- hdu 4782 Beautiful Soup 2013成都区域赛 大模拟
- Beautiful Soup
- Beautiful Soup
- Beautiful Soup
- Beautiful Soup
- Beautiful Soup
- Beautiful Soup 中文文档
- Beautiful Soup 中文教程
- Beautiful Soup 中文文档
- IOS成长之路-Nsstring中搜索方法rangeOfString
- Linux中shell文件操作大全
- 时间组件 My97
- jquery写的万年历的小例子
- SAP HANA: 列式内存数据库评测
- HDU 4782 Beautiful Soup
- ASCII码表完整版
- [Linux]Fedora 20 MySQL安装配置
- 汉字编码简明对照表
- 如何在Linux下统计高速网络中的流量
- 编程语言之python学习第一天
- XCode中调整字体大小
- struts2,Jquery uploadify异步上传文件
- Android 学习笔记5:GUI编程