当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4964:Emmet

题目描述
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 programmer develop 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.

4.Handle symbol ‘*’
At the end of a tag, you may see a suffix "*%d". It indicates that this tag would be repeated "%d" times.
  For example
  ul#id1>li.classA*3>p*2 =>
  <ul id="id1">
    <li class="classA">
      <p></p>
      <p></p>
    </li>
    <li class="classA">
      <p></p>
      <p></p>
    </li>
    <li class="classA">
      <p></p>
      <p></p>
    </li>
  </ul>
输入解释
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 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.
输入样例
4
div>p>span
div.aa#bb.cc.ee>p#g>span.d
div.aa#bb.cc.ee>(p#g1>span.d1)(p#g2>span.d2)(p#g3>span.d3)
ul#id1>li.classA*3>p*2
输出样例

来自杭电HDUOJ的附加信息
Author SYSU
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4964

最后修改于 2020-10-25T23:18:28+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 131072/131072K(Java/Others)