Sicily 14257. Myvim Plugin

14257. Myvim Plugin

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

For every programmer, coding HTML & CSS is a very boring thing.

For example, writing an html tag <div> with id "div1" and class "col-md-3", you must write an html file like this:

<div id = "div1" class = "col3">

...

</div>

Too much unnecessary coding!!!

For convenience, some Web programmers have developed a vim plugin -- Emmet. By this tool, the programmer just need code "div#div1.col3" and then Emmet would transform it to "<div id = "div1" class = "col3"></div>". It is very
coollllll! Now you task is to write a program to perform this transformation.

Here are more details about you task:

1.       Handle multilevel tag.

"div>p>span" means there are 3 tags and tag <p> is in the tag "div", tag <span> is in the tag "p".

So, the right answer is "<div><p><span></span></p></div>"

2.    Every tag may have zero or one id and any amount of classes.

A string (only consisting of letters and digits) after ‘#‘ is an id name.

A string (only consisting of letters and digits) after ‘.‘ is a class name.

If a tag has id and classes at the same time, you must output the id first.

If a tag has more than one class, you must output them by the order according to the input.

For example

"div.aa#bb.cc.ee>p#g>span.d" =>

<div id="bb" class="aa cc ee">

<p id="g">

<span class="d"></span>

</p>

</div>"

3.       Handle parentheses.

Use parentheses to deal with sibling relation among tags!

For example

<div id="bb" class="aa cc ee">

<p id="g1"><span class="d1"></span></p>

<p id="g2"><span class="d2"></span></p>

<p id="g3"><span class="d3"></span></p>

</div>

can be obtained by "div.aa#bb.cc.ee>(p#g1>span.d1)(p#g2>span.d2)(p#g3>span.d3)"

If the input string contains parentheses, the rightmost ‘)’ will be the last character of this string.

Input

The first line of input contains an integer N (N<=50), indicating the number of strings you need to transform.

The following N lines, each consists of an input string. No string has more than 120 chars and the result would not have more than 1000 chars. Tag name, class name and id only contain English letters and digits. It is guaranteed
that the input string is valid.

Output

Output N lines each consisting of a string that is the result of the transformation. More details about the output format can be seen from the sample output. You should follow the output format strictly. No extra space or new
line character is allowed in the output.

Sample Input

3div>p>spandiv.aa#bb.cc.ee>p#g>span.ddiv.aa#bb.cc.ee>(p#g1>span.d1)(p#g2>span.d2)(p#g3>span.d3)

Sample Output

<div><p><span></span></p></div><div id="bb" class="aa cc ee"><p id="g"><span class="d"></span></p></div><div id="bb" class="aa cc ee"><p id="g1"><span class="d1"></span></p><p id="g2"><span class="d2"></span></p><p id="g3"><span class="d3"></span></p></div>

Problem Source

SYSUCPC 2014 Preliminary (Online) Round

#include <iostream>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;

string T;

bool OnlyLD(char C) { return (('0' <= C && C <= '9') || ('A' <= C && C <= 'Z') || ('a' <= C && C <= 'z')); }

void Part(int st, int ed) {

	string name, id, classes;
	int p = st;

	while (p <= ed) {
		if (OnlyLD(T[p])) {
			int sp = p;
			for (; p < ed && OnlyLD(T[p]); p++);
			name = T.substr(sp, p - sp);
			cout << (name.size() > 0 ? "<" : "") + name;
		}
		if (T[p] == '(') {
			int sp = ++p, count = 1;
			for (; p < ed; p++) {
				if (T[p] == ')') count--;
				if (T[p] == '(') count++;
				if (count == 0) break;
			}
			Part(sp, min(p, ed));
			p++;
		}
		if (T[p] == '.') {
			int sp = ++p;
			for (; p < ed && OnlyLD(T[p]); p++);
			classes += (classes.size() > 0 ? " " : "") +  T.substr(sp, p - sp);
		}
		if (T[p] == '#') {
			int sp = ++p;
			for (; p < ed && OnlyLD(T[p]); p++);
			id = T.substr(sp, p - sp);
		}
		if (p == ed || T[p] == '>') {
			if (id.size() > 0) cout << " id=\"" + id + "\"";
			if (classes.size() > 0) cout << " class=\"" + classes + "\"";
			cout << (name.size() > 0 ? ">" : "");

			if (T[p] == '>') Part(p + 1, min((int)T.size(), ed));

			break;
		}
	}

	cout << (name.size() > 0 ? "</" : "") + name + (name.size() > 0 ? ">" : "");
}

int main() {

	std::ios::sync_with_stdio(false);

	int CaseNum;
	cin >> CaseNum;
	getline(cin, T);
	while (CaseNum--) {
		getline(cin, T);
		Part(0, T.size());
		cout << endl;
	}
	return 0;
}
时间: 2024-10-17 17:49:57

Sicily 14257. Myvim Plugin的相关文章

question --&gt; maven assembly plugin 修改文件默认权限

使用maven assembly plugin插件添加执行脚本时,发现默认权限为644,还需要手动添加执行权限.这很麻烦,于是查看文档 官方文档 http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_fileSet fileMode String Similar to a UNIX permission, sets the file mode of the files included. THIS IS

android-studio的gradle plugin配置相关的一些记录

感觉就是越高的Gradle版本对应的plugin越高. 你妹的,是不是2.10版本低于2.2版本,我还以为是2.10版本高于2.8.2.9版本呢.每次用2.10版本构建,用1.2.2等都不行.提示最低要求vesion为2.2,擦. classpath 'com.android.tools.build:gradle:1.2.2'//提示会有警告要求最底的Gradle版本是2.2,以上gradle版本为2.3,4,5,6....应该都可以,不过建议plugin本版不要过低,有些会不支持. class

[All in one WP Migration plugin] 搬迁wordpress 站点

为了方便大家去轻松的migrate 一个wordpress站点, 有developer开发出了一款插件----------All in one WP Migration ;这样大家就可以不用像之前一样要去分别备份数据库和网站文件了; 1. 首先, 在需要搬迁的旧站点和新站点的后台都需要去安装这个 All in one WP Migration plugin; 2. 在旧站点, 右键plugin, 点击export, 这样的操作是为了导出整个网站的备份文件. 需要注意的细节如下; 2.1> 点击右

No plugin found for prefix &#39;jetty&#39; in the current project and in the plugin groups

现在Jetty的版本已经到9了,也早已经在Eclipse的门下了.所以有很多groupId,比如:org.eclipse.jetty.org.mortbay.jetty.这些都可以用的哦. 我在使用MyEclipse结合maven操作jetty作为开发的服务器,这开开发比较方便. 当我运行命令: jetty:run 出现: [ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin gro

Tomcat Maven Plugin部署Maven Web应用

Tomcat官方提供了Maven插件用于部署基于Maven的Web应用,不同版本Tomcat使用的插件不同,不同版本插件的使用也有一定区别,详细信息可参考http://tomcat.apache.org/maven-plugin.html.下面记录的是我在Eclipse环境中使用Tomcat Maven Plugin-2.2在Tomcat7中部署Maven Web应用的配置过程: 第一步:配置Tomcat manager用户: 打开Tomcat根目录下conf目录中的tomcat_user.xm

override Ext.grid.plugin.RowExpander的方法不起作用

Ext版本4.2 覆盖方法: Ext.override(Ext.grid.plugin.RowExpander, {     setCmp: function (grid) {         var me = this,             rowBodyTpl,             features;         console.log('我是盖子..');         me.callParent(arguments);         me.recordsExpanded 

maven 的plugin 的使用

mvn [plugin-name]:[goal-name] mvn compiler:compile 这里写的十分详细: https://www.tutorialspoint.com/maven/maven_quick_guide.htm-------------------------------------------- What are Maven Plugins? Maven is actually a plugin execution framework where every tas

Webpack-源码三,从源码分析如何写一个plugin

经过上一篇博客分析webpack从命令行到打包完成的整体流程,我们知道了webpage的plugin是基于事件机制工作的,这样最大的好处是易于扩展.社区里很多webpack的plugin,但是具体到我们的项目并不一定适用,这篇博客告诉你如何入手写一个plugin,然后分析源码相关部分告诉你你的plugin是如何工作.知其然且知其所以然. 该系列博客的所有测试代码. 从黑盒角度学习写一个plugin 所谓黑盒,就是先不管webpack的plugin如何运作,只去看官网介绍. Compiler和Co

Android Gradle插件(plugin)版本(version)与Gradle、SDK Build Tools版本关系

具体关系如下图: 比如,Android Studio 2.0发布,其中有个新功能“Instant Run”,需要Android Gradle Plugin版本2.0.0以上,那么我们项目的.gradle文件就需要以下配置 buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.0.0' } } Android Gradle Plugin 2.0.0对应所需的Gradle版本为“2.10 or higher”