给定语句,按照语法翻译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. Liunx clear

    linux  clear命令  清空终端屏幕命令,另外,按Ctrl+L也可以达到同样的效果. init 0   关闭Liunx init 4   安全模式 init 6   重启Liunx

  2. istream_iterator和ostream_iterator

    总结: istream_iterator<T>in(strm);T指明此istream_iterator的输入类型,strm为istream_iterator指向的流 提供了输入操作符(& ...

  3. PAT 1024 科学计数法 (20)(精简版代码+思路+推荐测试样例)

    1024 科学计数法 (20)(20 分) 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+-][0-9]+, ...

  4. (O)编写可维护的代码示例(原创)

    图片轮播: /*广告图片数组*/ var imgs=[ {"i":0,"img":"images/index/banner_01.jpg"} ...

  5. Mac OS 10.12 - 在VMwear Workstation12.5.2中以两种方式进入恢复模式(Recovery)!!!

    注意:如果你打算安装Mac OS10.12 到虚拟机里面学习,那么我强烈建议你在没有安装任何其它软件之前,按照我这篇博客来进入恢复模式(Recovery),禁用Rootless机制!!!这样处理后,你 ...

  6. Tomcat的下载、安装、启动与关闭

    ubuntu server 16.04 从官网下载 Binary Distributions 版本的相应的压缩包, https://tomcat.apache.org/download-90.cgi ...

  7. How to Change MAC Address on Ubuntu

    1 Open Terminal.   2 Log in as root so type: sudo -i and then write your password.   3 View your cur ...

  8. Snownlp

    from snownlp import SnowNLP text='宝贝自拍很帅!!!注意休息-' s=SnowNLP(text) #分词print(s.words) #词性for tag in s. ...

  9. Sketch 和 PS中的设计图如何实现“自动切图”?

    切图是很多UI设计师的一项日常工作.平时做完设计图,要将设计稿切成便于制作成页面的图片,并标注好尺寸和间距,交付给前端来完成html+css布局的静态页面,有利于交互,形成良好的视觉感. 但有的认为前 ...

  10. base64编码是什么

    首先明确一点base64 是一种编码格式.就想utf-8一样,能在电脑上表示所有字符,或者换句话说通过编码能让电脑理解你想要标识的字符(因为电脑只知道0和1 ) 就像ascII 中 0100 0001