Boolean String Expression 字符串表达式

Problem Description
Mike needs a bike and he decides to buy a second-hand one to save money. Luckily, he has found a second-hand goods BBS. However, there are so many messages there and it will be extremely boring for him to look through all those messages and figure out which one contains the information he needs. So he decides to write a program to do this.

The problem is: how to determine whether a message is about selling a bike. Mike decides to use a keyword-find-based algorithm. First choose some keywords and then the program checks whether a message contains these keywords or not. For example, he wants to find messages that contain 'bike'，and at the same time have 'sell' or don't have 'buy' ("bike on sell", "bike", "sell bike and buy …"are all what he needs, but "buy bike" is not). Of course he wants his program can be used to handle things more than buying a bike.

As the string matching nature of the keyword-find-based algorithm, regular expression should be quite suitable here. But after a second thought, he throws it away: he even can't figure out what the corresponding regular expression is for a simple query "don't have the word 'buy'".

After further thinking of this problem, Mike comes up with a great idea: combining string matching with Boolean algebra! He names it as "Boolean String Expression".

Formally, a Boolean String Expression is composed of normal strings, ‘&’(and), ‘|’(or) and ‘!’(not). A Boolean String Expression s matches a message M when:
1. s is a normal string, and it's a substring of M
2. s = a & b, a and b are both Boolean String Expressions that match M
3. s = a | b, a and b are both Boolean String Expressions, and at least one of them matches M
4. s = ! a, a is Boolean String Expression which doesn't match M

Precedence of the three operators is: ‘!’ > ‘&’ > ‘|’. And parenthesis can be used to change precedence of operators. Mike's query can be easily expressed as:
Mike is very satisfied with this solution, but he comes to another problem: nearly all expressions can be changed into another form with the same meaning. For example, "bike & (sell | !buy)" has a equivalent form of:
(bike & sell) | (bike & !buy)
It may seem to be obvious to you. However, it confuses Mike a lot and he needs your help to write a problem to check whether two Boolean String Expressions are equivalent. (Equivalent here means: all messages that match one expression will match the other, all messages that don't match one expression will not match the other too)

Input
The first line contains an integer indicating the number of test cases (<=30).
Each test case contains three lines: The first line is an alphabet that contains only lower case letters. Suppose all messages we care about are only composed of those letters. The second line and 3rd line are two Boolean String Expressions. The expression contains only characters from the alphabet and '&', '|', '!' , and its length is no more than 20.

Output
For each test case, output a line of 'Yes' if the two expressions are equivalent, 'No' otherwise.

Sample Input
4
abcdefghijklmnopqrstuvwxyz
abc
a&(b|c)
a&b|c
ab
ab&!a
ab&!b
ab
a|b
a|!a

Sample Output
Yes
No
Yes
No

Java正则表达式无法匹配 ^匹配字符串开头 却冰崩匹配成功 为什么？
package regular_expression; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { Pattern pattern = Pattern.compile("^the"); Matcher matcher1 = pattern.matcher("the is"); Matcher matcher2 = pattern.matcher("there"); boolean matches1 = matcher1.matches(); boolean matches2 = matcher1.matches(); System.out.println(matches1); System.out.println(matches2); } } ![图片说明](https://img-ask.csdn.net/upload/201812/03/1543840422_233281.png)
Spring任务调度的问题
<p>需求:现在有个静态的boolean变量,需要根据给出的条件来控制变量的值,条件是一个Bean,代码如下</p> <p> </p> <pre name="code" class="java">import java.io.Serializable; import java.util.Date; public class TaskTime implements Serializable { private static final long serialVersionUID = 5050138699568912212L; private String expression; private Date startTime; private Date endTime; // Getter And Setter } </pre> <p> </p> <p>字段expression是一个CronExpression任务表达式</p> <p> </p> <p>当这个字段不为空或不是空字符串时,要根据表达式来控制boolean变量</p> <p>当表达式字段为空或空字符串时,要根据startTime把boolean变成true,endTime把boolean变量变成false</p> <p> </p> <p>可以给任务调度的方法如下:</p> <p> </p> <p>  </p> <pre name="code" class="java">private static boolean isRunning = false; public boolean run(){ isRunning = true; return isRunning; } public boolean stop(){ isRunning = false; return isRunning; } </pre> <p> </p> <p> </p> <p>请教如何来配置一个Spring任务调度来控制这个变量</p>

《MySQL 性能优化》之理解 MySQL 体系结构

Python+OpenCV实时图像处理

2020年一线城市程序员工资大调查

python爬取百部电影数据，我分析出了一个残酷的真相
2019年就这么匆匆过去了，就在前几天国家电影局发布了2019年中国电影市场数据，数据显示去年总票房为642.66亿元，同比增长5.4%；国产电影总票房411.75亿元，同比增长8.65%，市场占比 64.07%；城市院线观影人次17.27亿，同比增长0.64%。 看上去似乎是一片大好对不对？不过作为一名严谨求实的数据分析师，我从官方数据中看出了一点端倪：国产票房增幅都已经高达8.65%了，为什...

Windows可谓是大多数人的生产力工具，集娱乐办公于一体，虽然在程序员这个群体中都说苹果是信仰，但是大部分不都是从Windows过来的，而且现在依然有很多的程序员用Windows。 所以，今天我就把我私藏的Windows必装的软件分享给大家，如果有一个你没有用过甚至没有听过，那你就赚了????，这可都是提升你幸福感的高效率生产力工具哦！ 走起！???? NO、1 ScreenToGif 屏幕，摄像头和白板...

AI 没让人类失业，搞 AI 的人先失业了

2020年，冯唐49岁：我给20、30岁IT职场年轻人的建议

B站是个宝，谁用谁知道???? 作为一名大学生，你必须掌握的一项能力就是自学能力，很多看起来很牛X的人，你可以了解下，人家私底下一定是花大量的时间自学的，你可能会说，我也想学习啊，可是嘞，该学习啥嘞，不怕告诉你，互联网时代，最不缺的就是学习资源，最宝贵的是啥？ 你可能会说是时间，不，不是时间，而是你的注意力，懂了吧！ 那么，你说学习资源多，我咋不知道，那今天我就告诉你一个你必须知道的学习的地方，人称...

【蘑菇街技术部年会】程序员与女神共舞，鼻血再次没止住。（文末内推）

Java校招入职华为，半年后我跑路了

​两年前不知如何编写代码的我，现在是一名人工智能工程师

loonggg读完需要5分钟速读仅需 2 分钟大家好，我是你们的校长。我知道大家在家里都憋坏了，大家可能相对于封闭在家里“坐月子”，更希望能够早日上班。今天我带着大家换个思路来聊一个问题...

&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;meta http-equiv="X...
Spring框架|JdbcTemplate介绍

2020年2月中国编程语言排行榜

B 站上有哪些很好的学习资源?

24岁的程序员，还在未来迷茫，不知道能不能买得起房子