程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Sicily 14257. Myvim Plugin

Sicily 14257. Myvim Plugin

編輯:C++入門知識

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

with id "div1" and class "col-md-3", you must write an html file like this:

 

 

 

...

 

 

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 "

  ". 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

is in the tag "div", tag is in the tag "p".

So, the right answer is "

 

"

 

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" =>

 

 

 

 

 

 

 

 

"

 

3. Handle parentheses.

Use parentheses to deal with sibling relation among tags!

For example

 

 

 

 

 

 

 

 

 

 

 

 

 

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



 

 

 

 

 

Problem Source

SYSUCPC 2014 Preliminary (Online) Round

#include 
#include 
#include 
#include 
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 ? " 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;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved