编程介的小学生 2017-08-27 07:30 采纳率: 20.5%
浏览 827
已采纳

Gensokyo Forbidden Words

In Gensokyo (幻想郷), there are many forbidden words such as "PAD", "baka⑨", and "sukima babaa". Hieda no Akyu (稗田阿求), the ninth Child of Miare with ability to not forget anything she sees and record Gensokyo's history, is who maintains the system of Gensokyo Forbidden Words. Currently, the system uses glob to match the forbidden words. The rules of glob are as follows:

the asterisk character ("*") substitutes for any zero or more characters;
the question mark ("?") substitutes for any one character;
characters enclosed in square brackets ("[" and "]") substitute for all the characters in their ranges:
the string enclosed by the brackets cannot be empty (thus, "[][!]" matches the three characters '[', ']' and '!');
two characters separated by '-' denote a range (thus, "[]-]" matches just the two characters ']' and '-', and "[--0]" matches the three characters '-', '.', '/' and '0');
an expression "[!...]" substitute for all the characters not in their ranges, the string enclosed by the brackets cannot be empty;
an expression "[^...]" is invalid.

Recently, Akyu is planning to upgrade the system to use more powerful regex (regular expression). The rules of regex are as follows:

the asterisk character ("*") indicates there are zero or more of the preceding element. for example, ab*c matches "ac", "abc", "abbc", "abbbc", and so on;
the question mark ("?") indicates there is zero or one of the preceding element. for example, colou?r matches both "color" and "colour";
the dot character (".") matches any single character;
a bracket expression ("[...]") matches a single character that is contained within the brackets:
the string enclosed by the brackets cannot be empty;
two characters separated by '-' denote a range;
an expression "[^...]" matches a single character that is not contained within the brackets;
the "-" character is treated as a literal character if it is the last or the first character within the brackets. the "]" character can be included in a bracket expression if it is the first character.
Input

The input contains lines of valid glob, and is extremely large! It's guarantee that all brackets are well balanced, so "[" and "]" are invalid, but "[[]" and "[]]" are valid. Process to the end of file.

Output

Output should contains lines of regex. There are no special judge for this problem!

Sample Input

PAD
[Pp]ad
[!i]Pad
?pad
baka[9]
baka[[]9[]]

  • babaa ... Sample Output

PAD
[Pp]ad
[^i]Pad
.pad
baka[9]
baka[[]9[]]
.* babaa
[.][.][.]
More Sample Input

[!]]
[]]
[][!]
More Sample Output

[^]]
[]]
[][!]

  • 写回答

1条回答

  • devmiao 2017-09-10 04:50
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器