编程介的小学生 2017-08-21 02:37 采纳率: 20.5%
浏览 760
已采纳

XML

Problem Description
In this problem, you are asked to determine if a given document satisfies the syntax of an XML-like language.

A simple XML-like document can be parsed as a sequence of the following:

  1. Plain text---ASCII codes between 32 and 127 (inclusive), with none of the following symbols: <, >, &
  2. The sequences:
  3. <
  4. >
  5. & These encode a <, >, or & respectively.
  6. &xHEX; HEX must be any even (positive) number of upper or lower case hexadecimal digits, and this represents the bytes given.
  7. Tag can be any lowercase alphanumeric string. This tag is pushed onto the context stack.
  8. This tag is not pushed onto the context stack (there is no closing context).
  9. This tag removes the context from the stack, which must be topmost on the stack.

By the time the entire document is parsed, the context stack is empty for a valid document. We should also note that the empty string is considered valid.

Input
You will be given a number of documents to process. Each document is given as one line oftext which may be empty. The input is terminated by the end of file.

Output
For each document given, print valid on a single line if it is a valid XML-like document,or invalid otherwise.

Sample Input
the quick brown fox.
the quick brown fox.
fox & socks.
3x+5>7
Null: &x00;
the quick brown fox.
the quick brown fox
fox & socks.
3x+5>7
Null: &x0;

Sample Output
valid
valid
valid
valid
valid
invalid
invalid
invalid
invalid
invalid

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-02 15:45
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?