Skip to content

11987: 【原1987】Simple Path

题目

题目描述

author: xjia 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1987

Description

Given a well-defined attribute-free XML segment, and many simplified XPath queries, you are required to find the number of matching paths for each of the query.

You are allowed to read the following web pages in case you are not familiar with XML and/or XPath.

In this task, our XPath queries are simplified that each query only contains tag names, slashes (/) and dots (.).

  • If the slash appears as the first character of the query, it means the root.
  • Two consecutive dots mean the parent of current node.
  • A single dot means the current node.
  • If the query doesn't specify the root, it can match any node at the beginning.

The given XML segment will NOT contain attributes (attribute-free). For example, will NOT appear in this task but will.

See samples below for more details. Try to understand the task at your best and good luck!

Input Format

The first line is a well-defined attribute-free XML segment. Following lines are the lines to match. Only 8-bit ASCII printable characters will appear in the input.

Output Format

For each line to match, output the number of paths matched.

Sample Input 1

<words><word>Hello</word><word>World</word></words>
/words
/words/word
/word
word
words
words/word

Sample Output 1

1
2
0
2
1
2

Sample Input 2

<a> <b><c>1</c></b> <b> <x><c>2</c></x> <c>3</c> <d>4</d> </b> <b><d><x>5</x></d></b> </a> <x>6</x>
x
b/x
b/c
b//c
b/./c
b/x/c
b/d
b/c/../d
b/y/../d
./x
./b/c/../../b/d
/a/b/c/../../b/x/c

Sample Output 2

3
1
2
0
2
1
2
1
0
2
4
2

Limits

Time limit: 1000ms, memory limit: 30000kb.

Oops! 本题目还没有解答!

助教老师们编题的速度,已经超过了解题的速度!

OJ翻了一新,但本解答集还大多用的是2017-2019级,甚至更早的同学们贡献的答案。

如果你已经AC了,可以的话,请您参考添加页面,与大家一起分享你的题解!