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个数的某个排列,此排列的漂亮值为这个排列全部的区间最大公约数之和.然后这个集合的 ...
随机推荐
- es5 api
ES5 Object.create(prototype, descriptors) //创建对象 var o1 = {foo:'bar'}; var o2 = new Object(); //Obje ...
- MFC 动态创建控件
动态控件是指在需要时由Create()创建的控件,这与预先在对话框中放置的控件是不同的. 一.创建动态控件: 为了对照,我们先来看一下静态控件的创建. 放置静态控件时必须先建立一个容器,一 ...
- c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow
c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow fcgio.cpp:50: error ...
- eclipse svn插件显示作者
在另一台电脑里安装了SVN插件后,发现项目文件后面只有版本号,没有作者名字了,找了很久才找到了,现记录在这里. window->preferences->team->svn-> ...
- 求最小的k个数
和高速排序有点类似,利用高速排序的划分算法, 划分算法见http://blog.csdn.net/buyingfei8888/article/details/8997803 依据int partiti ...
- MongoDB(三)mongoDB下载和安装
软件下载 下载mongodb最新的包:http://www.mongodb.org/downloads 下载mongodb可视化界面,mongoVUE:http://download.csdn.net ...
- [置顶] 内存映射失败MapViewOfFile 失败 返回 8
问题描述1 在使用内存映射方式读写数据时,将文件A的内容拷贝至文件B中,偶尔会出来文件拷贝后的文件,内容为空,或部分为空 问题分析1 怀疑是内存映射方式读写数据的稳定性(可笑的怀疑,内存映射可以Win ...
- Dojo实现Tabs页报错(一)
1.在用Dojo写tab页的过程中出现了一些错误 dojo源码如下: <%-- Document : grid Created on : 2013-12-15, 18:05:47 Author ...
- [cocos2d-x] 让精灵响应触摸 并把方向旋转到相对应的角度
在cocos2d-x里面 想要把一个精灵从原位置移动到用户所触摸到的点 , 并且把精灵的方向旋转相对应的弧度,可以参考一下我的做法 我这里的精灵是用一条鱼, 用户触摸后鱼就移动到所触摸的点, 并且移 ...
- Python开发环境Spyder安装方法
Spyder(Scientific PYthon Development EnviRonment)是一个强大的交互式 Python 语言开发环境,提供高级的代码编辑.交互测试.调试等特性,支持包括 W ...