HDU4782——Beautiful Soup(模拟)
来源:互联网 发布:软件开发工程师有多累 编辑:程序博客网 时间:2024/06/02 16:02
题目大意
题目给你一些没有经过排版的HTML代码,让你按照一定的格式排版好,去掉多余空格,保持规则的缩进。
题目分析
注意的地方就是’ < /html >’ 和 ‘< html >’ 可能在同一行。
其实题目本身并没有多少技巧,就是锻炼基本的代码功底。刚开始写的时候,写了一坨稀烂的代码,结果出错之后的Debug变得非常困难。所以看似这种随意的代码风格能节省时间,其实维护的成本要高得多得多。后来又重新敲了一遍,发现其实在你有了一个全局的规划之后再动手,代码会更加清晰,出错之后也更易发现。
#include <iostream>#include <algorithm>#include <cmath>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;typedef long long LL;const int INF = 0x7fffffff;const int MOD = 1e9 + 7;const int N = 1e5 + 10;char c;int T;int Cas = 2, Len = 0;bool isSpace(char c) { return c == 32 || c == 9 || c == 10;}void Skip() { while((c = getchar()) && isSpace(c)) ;}void nextCase() { if(T == 0) { puts(""); exit(0); } printf("\nCase #%d:", Cas++); T--;}void newLine() { putchar('\n'); for(int i = 0; i < Len; i++) putchar(' ');}void printTags() { string Temp; while((c = getchar()) && c != '>') Temp += c; int l = Temp.size(); if(Temp[0] == '/') { Len--; newLine(); printf("<%s>", Temp.c_str()); } else if(Temp[l - 1] != '/') { newLine(); printf("<%s>", Temp.c_str()); Len++; } else { newLine(); printf("<%s>", Temp.c_str()); } if(Len == 0) nextCase();}void printText() { newLine(); putchar(c); while((c = getchar()) && c != '<') { if(isSpace(c)) { Skip(); if(c == '<') break; putchar(' '); } putchar(c); }}int main() {#ifdef Tally_Ho freopen("in.txt", "r", stdin);#endif // Tally_Ho scanf("%d", &T); c = getchar(); printf("Case #1:"); T--; while(true) { if(isSpace(c)) { Skip(); } else if(c == '<') { printTags(); c = getchar(); } else { printText(); } } return 0;}
0 0
- HDU4782——Beautiful Soup(模拟)
- hdu - 4782 - Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup(模拟)
- hdu 4782 Beautiful Soup(模拟)
- HDU4782 模拟
- HDU 4782 Beautiful Soup 模拟
- HDU 4782 Beautiful Soup 模拟
- HDU-4782-Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup --模拟
- 2013成都国赛 hdu 4782 Beautiful Soup (模拟)
- Learn Beautiful Soup(3)——使用Beautiful Soup进行查找
- Learn Beautiful Soup(3)——使用Beautiful Soup进行查找
- 基于Beautiful Soup 4.2.0文档的学习记录(1)——find()、find_all()、findAll()
- 基于Beautiful Soup 4.2.0文档的学习记录(2)——CSS选择器
- 基于Beautiful Soup 4.2.0文档的学习记录(3)——get_text()、get()
- 网络爬虫系列笔记(3)——Beautiful Soup库
- Learn Beautiful Soup(1)——环境搭建
- Learn Beautiful Soup(2)——BeautifulSoup的对象
- UML之状态图
- Thread - JConsole
- php导出excel
- Spring4.0使用websocke遇到的一些问题
- 孙鑫 VC++深入详解——学习笔记
- HDU4782——Beautiful Soup(模拟)
- 关于Cocos2d-x的一些认识(5)
- sleep和wait的区别
- 【C/C++学院】(12)C++标准模板库STL
- Cocos2d-x之getVisibleSize,getContentSize,boundingBox,getContentSizeInPixels,convertToGL,convertToUI
- You are given a tetrahedron.
- win平台/linux平台下C/C++库文件引入问题
- linux c/c++ 帮助
- log4j日志级别