给定语句,按照语法翻译html并输出。
就是恶心的模拟,递归搞就行了
处理id和class时,在一个'>'内,先把遇到的id和class都push到一个容器中,然后再输出即可。优先输出id,然后是class
递归过程即为分解成head+context+end的样子

#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define RD(x) scanf("%d",&x)
using namespace std;
typedef pair<string, string> p;
#define MP make_pair
#define PB push_back
p tag(string a) {
if (a == "")
return MP("", "");
string x, y;
string b;
string name;
vector<string> id;
vector<string> classname;
int which = 0;
int i;
for (i = 0; i < a.length(); i++) {
if (a[i] == '.') {
if (which == 0)
name = b;
else if (which == 1)
id.PB(b);
else
classname.PB(b);
b = ""; which = 2;
} else if (a[i] == '#') {
if (which == 0)
name = b;
else if (which == 1)
id.PB(b);
else
classname.PB(b);
b = ""; which = 1;
} else {
b += a[i];
}
}
if (which == 0)
name = b;
else if (which == 1)
id.PB(b);
else
classname.PB(b);
b = ""; x = "<" + name;
if (id.size() != 0) {
x += " id=\"";
for (int i = 0; i < id.size(); i++) {
if (i)
x += " ";
x += id[i];
}
x += "\"";
} if (classname.size() != 0) {
x += " class=\"";
for (int i = 0; i < classname.size(); i++) {
if (i)
x += " ";
x += classname[i];
}
x += "\"";
}
x += ">";
y = "</" + name + ">";
return MP(x, y);
}
string work(string a) {
if (a[0] == '(') {
int x = 1, p;
for (p = 1; p < a.length(); p++) {
if (a[p] == '(')
x++;
if (a[p] == ')')
x--;
if (x == 0)
break;
}
string a1 = a.substr(1, p - 1);
string a2 = a.substr(p + 1);
return work(a1 + '>') + work(a2);
}
int q = a.find('>');
if (q == -1)
return ""; string s = work(a.substr(q + 1)); a = a.substr(0, q); int nn = 1;
if (a.find('*') != -1) {
int p = a.find('*');
sscanf(a.substr(p + 1).c_str(), "%d", &nn);
a = a.substr(0, p);
}
p tmp = tag(a);
string ret = tmp.first + s + tmp.second;
string ans = "";
for (int i = 0; i < nn; i++)
ans += ret;
return ans;
} char c[400];
int main() {
int _;RD(_);
while (_--){
scanf("%s", c);
puts(work((string)c + '>').c_str());
}
return 0;
}

hdu 4964 恶心模拟的更多相关文章

  1. HDU 4964 Emmet --模拟

    题意:给你一个字符串,要求把它按语法转化成HTML格式. 分析:这题其实不难,就是一个递归的事情,当时忽略了括号嵌套的情况,所以一直WA,后来加上这种情况后就过了.简直醉了. 处理id和class时, ...

  2. hdu 5071 vector操作恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=5071 对于每一个窗口,有两个属性:优先级+说过的单词数,支持8个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗 ...

  3. hdu 4930 斗地主恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4930 就是两个人玩斗地主,有8种牌型,单张,一对,三张,三带一,三带对,四带二,四炸,王炸.问先手能否一次出完牌 ...

  4. hdu 6020 MG loves apple 恶心模拟

    题目链接:点击传送 MG loves apple Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Ja ...

  5. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  6. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  7. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  8. HDU 2568[前进]模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...

  9. [UVA227][ACM/ICPC WF 1993]Puzzle (恶心模拟)

    各位大佬都好厉害…… 这个ACM/ICPC1993总决赛算黄题%%% 我个人认为至少要绿题. 虽然算法上面不是要求很大 但是操作模拟是真的恶心…… 主要是输入输出的难. 对于ABLR只需要模拟即可 遇 ...

随机推荐

  1. 探索未知种族之osg类生物---器官初始化一

    我们把ViewerBase::frame()比作osg这类生物的肺,首先我们先来大概的看一下‘肺’长什么样子,有哪几部分组成.在这之前得对一些固定的零件进行说明,例如_done代表osg的viewer ...

  2. python提取分析表格数据

    #/bin/python3.4# -*- coding: utf-8 -*- import xlrd def open_excel(file="file.xls"): try: d ...

  3. Scrapy框架学习笔记

    1.Scrapy简介 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网 ...

  4. 【解决办法--实测可行】Partition 1 does not start on physical sector boundary.

    新的硬盘使用fdisk进行划分的时候有提示Partition 1 does not start on physical sector boundary.后面按网上找的办法,在fdisk进行分区的时候, ...

  5. 大神你好,可以帮我P张图吗?

    韩国版的求大神帮我P张图,看得有点下巴脱臼啊!哈哈哈哈哈哈哈~ 感觉照片拍得很尴尬,请大神P得更有动感 拍了跳跃照片,但内衣露出来一点,能帮忙去掉吗 不喜欢没穿制服的样子,请帮忙加上制服 ​ 希望背景 ...

  6. Python 常用模块之re 正则表达式的使用

    re模块用来使用正则表达式.正则表达式用来对字符串进行搜索的工作.我们最应该掌握正则表达式的查询,更改,删除的功能.特别是做爬虫的时候,re模块就显得格外重要. 1.查询 import re a = ...

  7. PHP 过滤特殊符号

    function strFilter($str){ $str = str_replace('`', '', $str); $str = str_replace('·', '', $str); $str ...

  8. windows mysql主 Linux mysql 从 主从同步,读写分离

    Mysql –master linux-slave 一.My.ini: Server-id=1 relay-log=relay-bin relay-log-index=relay-bin-index ...

  9. Two Sum II - Input array is sorted LT167

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  10. centos 6.5 配置ssh免登录

    生成密匙: ssh-keygen -t rsa 会生成 id_rsa  id_rsa.pub id_rsa:私匙 id_rsa.pub:公匙 配置当前机器免登录: cp id_rsa.pub auth ...