笔经面经分享之亚马逊笔试题第二弹。希望通过本帖,能够对正在找工作的同学或者将要找工作的同学提供微薄之力。
--小站小编
1笔试题
下面是来自于亚马逊的编程笔试题,感兴趣的同学可以先自己想想解题思路:
Please implement a simple logic rule, the input is a set of logic formula, the format is like a1,a2,a3,…,an->b, which means a1,a2,a3,…an can deduce b. It meets the following rules:
1.If A->B B->C then A->C
2.If A,B->C D->A then D,B->C
3.If A,B->C then B,A->C
The input contains two lines:
1.The first line contains n (100>n>0) base formulas, separated by spaces
2.The second line contains m (100>m>0) formulas that need to check true or false according to above n formulas, separated by spaces
The output should be m lines, if the i-th formula in the second line can be deduced by the n base formulas, the i-th line should be "true", otherwise, "false".
Each element is a case sensitive alphabet, to simplify the parsing work, “->” is replaced by ">", there might be more than 1 character on the left side and only one on the right side, the following is an example:A,B,C>D
Sample Input and Output
Input
A>B B>C
A>C
Output
true
Input
A,B>C D,E>A E>B
E,D>C F,E>C
Output
true
false
Input
A>B A,B>C
A>C
Output
true
Please complement thematchRulemethod inSolutionclass:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String baseRules = br.readLine();
String checkingRules = br.readLine();
matchRule(baseRules, checkingRules);
br.close();
isr.close();
}
private static void matchRule(String baseRules, String checkingRules) {
}
}
--------------我是华丽丽的分隔线----------------
2图简介
首先让我们对比一下几种数据结构:线性表&#x