模拟。其实这题就是题目比较长而已。。。读完题目就差不多了。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的更多相关文章

  1. hdu - 4782 - Beautiful Soup(模拟)

    题意:输出一堆乱排版的html标签,去多余空字符,转换为按缩进输出. 题目链接:pid=4782">http://acm.hdu.edu.cn/showproblem.php?pid= ...

  2. HDU 4782 Beautiful Soup --模拟

    题意: 将一些分散在各行的HTML代码整理成标签树的形式. 解法: 模拟,具体见代码的讲解. 开始没考虑 '\t' .. 代码: #include <iostream> #include ...

  3. HDU 4782 Beautiful Soup (模拟+注意细节)

    思路就是用栈模拟,不用开实体的栈,直接记一个top指针就行. 说说这题的细节: 1.tag标签里的内容不要动,原样输出.比如<p aa bb cc>,就这样输出就行,不要删空格.题目中说了 ...

  4. HDU 5062 Beautiful Palindrome Number(数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...

  5. HDU - 6351 Beautiful Now

    Beautiful Now HDU - 6351 Anton has a positive integer n, however, it quite looks like a mess, so he ...

  6. HDU Redraw Beautiful Drawings 推断最大流是否唯一解

    点击打开链接 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 ...

  7. HDU 5321 Beautiful Set (莫比乌斯反演 + 逆元 + 组合数学)

    题意:给定一个 n 个数的集合,然后让你求两个值, 1.是将这个集合的数进行全排列后的每个区间的gcd之和. 2.是求这个集合的所有的子集的gcd乘以子集大小的和. 析:对于先求出len,len[i] ...

  8. HDU 5179 beautiful number 数位dp

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...

  9. HDU 5321 Beautiful Set 漂亮集合

    题意:给定一个集合,含有n个数.浙理工先生和杭电先生各自有计算这个集合漂亮值的方法. 浙理工先生的计算方法是:对于这个n个数的某个排列,此排列的漂亮值为这个排列全部的区间最大公约数之和.然后这个集合的 ...

随机推荐

  1. 10_Segue Example

    10 // // ViewController.swift // Segues Example // // Created by ZC on 16/1/10. // Copyright © 2016年 ...

  2. SSD的来由与优势

           SSD,对于很多人来说,它现在已不再是个很陌生的名词,有些网友谐趣的把它称作“湿湿的”,这里既有谐音的意味,也有称赞SSD意思.虽然大家对SSD已不算陌生,但恐怕对SSD的历史也所知不多 ...

  3. 简单测试运行时类信息(RTTI),附详细例子

    新建一个单元文件,填写如下代码,然后保存为 ClassInfoUnit.pas,这里定义了一个结构,用来读取指定类的信息. unit ClassInfoUnit; interface uses Cla ...

  4. http 响应头之location

    <pre name="code" class="html">jrhmpt01:/root# cat login_yylc.pl use LWP::U ...

  5. JavaEE Tutorials (13) - 使用锁定控制对实体数据的并发访问

    13.1实体锁定和并发概述180 13.1.1使用乐观锁定18113.2锁模式181 13.2.1设置锁模式182 13.2.2使用悲观锁定183

  6. linux之screen命令

    linux平台下想同时运行多个操作,执行多个程序或命令:命令行就一个,要想同时执行多个命令如何操作? 一个screen命令即可: Centos操作系统默认没有安装screen: 安装方法: Cento ...

  7. java list基本用法

    List<E>([]内的内容可省略),与数组类似: 实例化:List[<数据类型>] list = new ArrayList[<数据类型>](); 获得集合内元素 ...

  8. js学习笔记第一课(js基础知识)

    1.js代码在浏览器中执行. 2.js代码直接插入网页中需包含在 <script language="javascript"> js代码 </script> ...

  9. QT全局热键(用nativeKeycode封装API,不跨平台)

    在网上找了很长时间,大家都提到了一个QT全局热键库(qxtglobalshortcut),支持跨平台.在这篇文章中,我将只展示出windows平台下全局热键的设置. 这里提供的方法是在MyGlobal ...

  10. 超轻量级PHP SQL数据库框架

    <?php /** * ! Medoo 0.8.5 - Copyright 2013, Angel Lai - MIT license - http://medoo.in */ class me ...