Sicily 14257. Myvim Plugin

Source: Internet
Author: User
Tags tag name

14257. Myvim Plugin Constraints

Time limit:1 secs, Memory limit:256 MB

Description

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

For example, writing a HTML tag <div> with ID ' div1 ' and class ' col-md-3 ', you must write a HTML file like this:

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

...

</div>

TOO MUCH unnecessary coding!!!

For convenience, some WEB programmers has 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 "Clas s = "col3" ></div> ". It is very coollllll! Now, task is to write a program to perform this transformation.

Here is more details on you task:

1. Handle multilevel tag.

"Div>p>span" means there is 3 tags and tag <p> be in the tag "div", tag <span> was in the tag "P".

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

2. Every tag may has zero or one ID and any amount of classes.

A string (only consisting of letters and digits) after ' # ' was an ID name.

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

If a tag has an 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 is 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 ') ' 'll be is the last character of this string.

Input

The first line of input contains a 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-chars and the result would not having more than-chars. Tag name, class name and ID only con tain 中文版 letters and digits. It is guaranteed, the input string is valid.

Output

Output N lines each consisting of a string, which is the result of the transformation. More details about the output format can is seen from the sample output. You should follow the output format strictly. No extra space or new line character are 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 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 (CO UNT = = 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)); 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;}

Sicily 14257. Myvim Plugin

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.