模拟。其实这题就是题目比较长而已。。。读完题目就差不多了。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. ODI中的CDC

    ODI中的CDC是通过一组所谓的日志知识模块(Journal Knowledge Module,JKM)实现的,在项目中加在了这些模块后,就可以在接口设计时选择全量数据,还是变化数据.   ODI共提 ...

  2. react-native 入门资源合集

    # 了解react-native React Native enables you to build world-class application experiences on native pla ...

  3. 沙朗javascript(两)正则表达式

          以下提到的文章javascript基础,今天我说些什么javascript正则表达式正确.      说到这首先要问了,什么是正則表達式,正則表達式能干什么? 正則表達式:一个正則表達式就 ...

  4. android 围绕中心旋转动画

    本文主要介绍Android中如何使用rotate实现图片不停旋转的效果.Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换(平移.缩放.旋转)产生动画效果 ...

  5. SQL函数经常用到的mark一下

    在项目开发过程中存储过程会用到很多SQL函数,经常用到的mark一下 1.经常用到的mark 一下 经常需要把id字符以','分隔传入存储过程然后SQL语句用in去搜索但是经常是这样的情况id 经常是 ...

  6. Sqoop mysql 数据导入到hdfs

    1.--direct 模式使用mysqldump 工具,所以节点上需要安装该工具,非direct 模式直接使用jdbc ,所以不需要 具体script参考如下: sqoop import --conn ...

  7. hrtimer 高精定时器使用例子

    在kernel,有个线程每个十秒往上层系统上报battery及USB的状态信息. 加入直接sleep 10 秒的话,插入USB的时候不能及时更新状态,这个时候就可以使用 hrtimer + wait ...

  8. C#_socket拆包_封包_模拟乱序包

    拆包一直是个硬伤呀,MLGB的,服务端各种乱数据,果断整理下 拆包思路:设计一个网络协议,一般都会分包,一个包就相当于一个逻辑上的命令. .如果我们用udp协议,省事的多,一次会收到一个完整的包,但U ...

  9. [转] iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用

    介绍: Grand Central Dispatch 简称(GCD)是苹果公司开发的技术,以优化的应用程序支持多核心处理器和其他的对称多处理系统的系统.这建立在任务并行执行的线程池模式的基础上的.它首 ...

  10. Protel 99SE PCB 打印技巧

    1. 打开 Protel99SE PCB 设计文档.从菜单File 下单击Print/Preview 打印预览菜单.出现PCB 打印预览介面. 2.从File 下单击 Setup Printer 设置 ...