hdu 4782 Beautiful Soupz
模拟。其实这题就是题目比较长而已。。。读完题目就差不多了。tag直接读就可以了,题目说了不用修改。然后整个题目就是让求text部分,严格按空格分开。注意每行前面空格个数。
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define REP(i, n) for(int i=0; i<n; i++)
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define CLR(a, b) memset(a, b, sizeof(a))
#define PB push_back
#define LL long long
using namespace std; const int N = 1000;
char ch[N], c;
vector<string> ans;
char stop[10] = "</html>"; int main()
{
//freopen("input.txt", "r", stdin);
int t, cas = 1;
scanf("%d", &t);
while(t --)
{
int cnt = 0;
ans.clear();
c = getchar();
while(true)
{
while(c == ' ' || c == '\n' || c == '\t') c = getchar();
if(c == '<')
{
ch[cnt ++] = '<';
while(c != '>')
{
c = getchar();
ch[cnt ++] = c;
}
ch[cnt] = '\0';
ans.push_back(ch);
cnt = 0;
if(!strcmp(ch, stop))
{
break;
}
c = getchar();
}
else
{
while(c != ' ' && c != '\n' && c != '<' && c != '\t')
{
ch[cnt ++] = c;
c = getchar();
}
ch[cnt] = '\0';
cnt = 0;
ans.push_back(ch);
}
}
cnt = 0;
bool flag = false;
printf("Case #%d:\n", cas ++);
REP(i, ans.size())
{
if(ans[i][0] == '<')
{
flag = false;
if(ans[i][1] != '/')
{ REP(j, cnt) putchar(' ');
cout << ans[i] << endl;
int len = ans[i].size();
if(ans[i][len - 2] != '/') cnt ++;
else continue;
ch[0] = '<';
ch[1] = '/';
FF(j, 1, len)
{
if(ans[i][j] == ' ')
{
ch[j + 1] = '>';
ch[j + 2] = '\0';
break;
}
ch[j + 1] = ans[i][j];
}
ch[len + 1] = '\0';
}
else
{
cnt --;
REP(j, cnt) putchar(' ');
cout << ans[i] << endl;
}
}
else
{
if(!flag)
{
REP(j, cnt) putchar(' ');
cout << ans[i];
flag = true;
}
else cout << " " << ans[i];
if(ans[i + 1][0] == '<') puts("");
}
}
}
}
hdu 4782 Beautiful Soupz的更多相关文章
- hdu - 4782 - Beautiful Soup(模拟)
题意:输出一堆乱排版的html标签,去多余空字符,转换为按缩进输出. 题目链接:pid=4782">http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 4782 Beautiful Soup --模拟
题意: 将一些分散在各行的HTML代码整理成标签树的形式. 解法: 模拟,具体见代码的讲解. 开始没考虑 '\t' .. 代码: #include <iostream> #include ...
- HDU 4782 Beautiful Soup (模拟+注意细节)
思路就是用栈模拟,不用开实体的栈,直接记一个top指针就行. 说说这题的细节: 1.tag标签里的内容不要动,原样输出.比如<p aa bb cc>,就这样输出就行,不要删空格.题目中说了 ...
- HDU 5062 Beautiful Palindrome Number(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...
- HDU - 6351 Beautiful Now
Beautiful Now HDU - 6351 Anton has a positive integer n, however, it quite looks like a mess, so he ...
- HDU Redraw Beautiful Drawings 推断最大流是否唯一解
点击打开链接 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 ...
- HDU 5321 Beautiful Set (莫比乌斯反演 + 逆元 + 组合数学)
题意:给定一个 n 个数的集合,然后让你求两个值, 1.是将这个集合的数进行全排列后的每个区间的gcd之和. 2.是求这个集合的所有的子集的gcd乘以子集大小的和. 析:对于先求出len,len[i] ...
- HDU 5179 beautiful number 数位dp
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...
- HDU 5321 Beautiful Set 漂亮集合
题意:给定一个集合,含有n个数.浙理工先生和杭电先生各自有计算这个集合漂亮值的方法. 浙理工先生的计算方法是:对于这个n个数的某个排列,此排列的漂亮值为这个排列全部的区间最大公约数之和.然后这个集合的 ...
随机推荐
- 安装64位Oracle 10g超详细教程
安装64位Oracle 10g超详细教程 1. 安装准备阶段 1.1 安装Oracle环境 经过上一篇博文的过程,已经完成了对Linux系统的安装,本例使用X-Manager来实现与Linux系统的连 ...
- 转: git常用命令
# git配置 #---------------------------------------------- #配置用户名和邮箱: $ git config --global user.name & ...
- DDR、DDR2、DDR3产品区别
DDR采用一个周期来回传递一次数据,因此传输在同时间加倍,因此就像工作在两倍的工作频率一样.为了直观,以等效的方式命名,因此命名为DDR 200 266 333 400. DDR2尽管工作频率没有变化 ...
- 让.net程序自动运行在管理员权限下
原文:让.net程序自动运行在管理员权限下 如何让.net程序自动运行在管理员权限下 VS2010 c# 编译的WINFORM程序 在Win7 以管理员身份运行 windows 7和vista提高的系 ...
- 如何使ListView具有像ios一样的弹性
ListView 是我们在开发过程中经常使用的控件之一,通常情况下,当我们没有对它进行自定义或者给添加headerview 或者footerView的时候,他都没有一个很好的反馈效果,但是相比较而言, ...
- kafka初探
http://www.infoq.com/cn/articles/kafka-analysis-part-1
- [学习笔记]今天开始学HTML5!
1,href和src的区别:href有“连接,引用”之意,指两者的连接关系,如<a href=""></a>,<link href="**. ...
- 经典阅读-《Effective C++》Item1:视C++为一个联邦语言
C++已经是个多重范型编程语言(multiparadigm programming language),一个同时支持过程形式(procedural).面向对象形式(object-oriented).泛 ...
- iphone抓取移动网络报文的方法
iphone抓取移动网络报文的方法 对iPhone进行越狱,网上有很多教程,这里不做说明.越狱后会有cydia这个app,首先对用户身份进行设置,选用开发者身份.打开这个应用,搜索openssh,找到 ...
- Object-c KVC的使用和举例
如果我们的对象需要使用KVC,必须符合object-c的非正式协议NSKeyValueCoding.我们可以简单的来理解KVC,即所有符合KVC机制的对象都看成一个字典(NSDictionary),对 ...