给定语句,按照语法翻译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. C# CashCode项目开发

    如果不是因为这个项目,我可以一辈子都接触不到识币器,更不会知道CashCode是干啥的. 从项目开始,到CashCode机器到桌面上测试,中间在网上找过资料,也联系过北京的技术,他们发来的PDF让我看 ...

  2. hdu 3368 曾经下过的棋

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3368 就是讲一种下棋的方法,很多人小时候也应该玩过,输入8*8的矩阵代表棋盘,*代表空位 D代表黑子, ...

  3. BZOJ1001或洛谷4001 [BJOI2006]狼抓兔子

    BZOJ原题链接 洛谷原题链接 显然就是求最小割. 而对于一个平面图有结论,最大流=最小割=对偶图最短路. 所以这题可用最大流或是转换为对偶图求最短路,这里我是用的对偶图. 虽然理论上按上界算,这题\ ...

  4. python 找出一篇文章中出现次数最多的10个单词

    #!/usr/bin/python #Filename: readlinepy.py import sys,re urldir=r"C:\python27\a.txt" disto ...

  5. mysql进程挂了

    .查看日志文件位置:cat /etc/my.cnf .搜索:cat /data/mysql/mysql-error.log|grep 'Shutdown complete' 3.进一步搜索:cat / ...

  6. 第五周Java学习总结(补)

    第五周java学习内容(补) 学习内容: File类方法的操作 public String getName() public boolean canRead() public boolean canW ...

  7. 2017/2/10:Manven简介与项目管理(入门)

    1.Maven工程的创建 2.使用Manven manven配置文件主要集中在 http://m.blog.csdn.net/article/details?id=50316383

  8. Devexpress VCL Build v2015 vol 15.1.2发布

    2015年马上过半年了.终于第一个大版出来了. What's New in 15.1.2 (VCL Product Line)   New Major Features in 15.1 What's ...

  9. 一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows

    https://www.luogu.org/problemnew/show/P2858 方程很好想,关键我多枚举了一次(不过也没多大关系) #include <bits/stdc++.h> ...

  10. python对数据类型的相关操作

    一.int的相关操作 int只有一个相关操作,bit_length()   用于计算一个数字的二进制长度 二.bool的相关操作 1.把数字转换成bool,除了0,返回的都是True a = 10 p ...