hdu 4964 恶心模拟
#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 恶心模拟的更多相关文章
- HDU 4964 Emmet --模拟
题意:给你一个字符串,要求把它按语法转化成HTML格式. 分析:这题其实不难,就是一个递归的事情,当时忽略了括号嵌套的情况,所以一直WA,后来加上这种情况后就过了.简直醉了. 处理id和class时, ...
- hdu 5071 vector操作恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=5071 对于每一个窗口,有两个属性:优先级+说过的单词数,支持8个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗 ...
- hdu 4930 斗地主恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4930 就是两个人玩斗地主,有8种牌型,单张,一对,三张,三带一,三带对,四带二,四炸,王炸.问先手能否一次出完牌 ...
- hdu 6020 MG loves apple 恶心模拟
题目链接:点击传送 MG loves apple Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Ja ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
- HDU 2568[前进]模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...
- [UVA227][ACM/ICPC WF 1993]Puzzle (恶心模拟)
各位大佬都好厉害…… 这个ACM/ICPC1993总决赛算黄题%%% 我个人认为至少要绿题. 虽然算法上面不是要求很大 但是操作模拟是真的恶心…… 主要是输入输出的难. 对于ABLR只需要模拟即可 遇 ...
随机推荐
- 利用spring boot构建一个简单的web工程
1.选择Spring InitiaLizr, jdk选择好路径 2.设置项目信息 3.这一步是设置选择使用哪些组件,这里我们只需要选择web 4.设置工程名和路径
- 案例情景--在一次Oracle 数据库导出时 EXP-00008;ORA-00904:EXP-00000: oracle不同版本导入导出规则
案例情景--在一次Oracle 数据库导出时: C:\Documents and Settings\Administrator>exp lsxy/lsxy@lsxy_db file=E:\lsx ...
- 如何快速学好Shell脚本?
Shell 语言作为类 Unix 系统的原生脚本,有着非常实用的价值.但对于很多刚刚接触 Shell 脚本的同学来说,搞懂 Shell 语言的语法却是一件非常困难的事情.甚至有人吐槽,或许没有谁能清楚 ...
- Codeforces 749C. Voting 模拟题
C. Voting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input o ...
- 检查mysql是否运行
netstat -tunple|grep mysql
- EL 11个内置对象
JSP开发人员可以在EL表达式中使用EL隐式对象,而不用任何显式的编码或声明.语法如下: ${隐式对象名} <!-- 获取EL隐式对象的引用 --> 在JSP页面中,可以使用JSP脚本来 ...
- nginx 域名(虚拟)部署nodejs项目
首先说下我的情况,Windows+mongodb开发的简单nodejs 小博客系统, 配置部署到centos7 nginx下,mongodb还是在我Windows机器下, 1.Linux安装node. ...
- IOS初级:UIAlertController
- (IBAction)signOutAction:(id)sender { //初始化,StyleActionSheet是对话框的样式 UIAlertController *alert = [UIA ...
- appium获取package和activity
输入命令adb shell dumpsys window w |findstr \/ |findstr name=然后在手机端打开app,电脑上按enter就即可显示 以微信为例子 appPackag ...
- 【Linux】zlib安装
zlib简介 zlib是提供数据压缩用的函式库,由Jean-loup Gailly与Mark Adler所开发,初版0.9版在1995年5月1日发表.zlib使用DEFLATE算法,最初是为libpn ...