javaSE复习(7)
1.KMP算法
使用KMP算法在主串 "abaabaabcabaabc" 中搜索模式串 "abaabc",到匹配成功时为止,请问在匹配过程中进行的单个字符间的比较次数是()。
10次
用于互斥时 初值为1
在一个并发编程环境中,P、V操作的信号量S初值为4,当前值为-1,则表示有多少个等待进程()
创建变量时 左右不能有空格
过滤空行:
cat app.log | grep -v '^$'
5 分钟搞懂布隆过滤器,亿级数据过滤算法你值得拥有! - 知乎
C语言:关系与逻辑运算符、运算符优先级_关系运算符-CSDN博客https://blog.csdn.net/sgbl888/article/details/123997358
import java.util.Scanner;
import java.util.*;
//牛客题解
public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);int productNum = in.nextInt();int wordsNum = in.nextInt();in.nextLine();Set<String> wordsDict = new HashSet<>();for (int i = 0; i < wordsNum; i++) {String temp = in.next();wordsDict.add(temp);}in.nextLine();List<Product> productList = new ArrayList<>();for (int i = 0; i < productNum; i++) {String name = in.next();int num = in.nextInt();in.nextLine();List<String> words = new ArrayList<>();Collections.addAll(words, in.nextLine().split(" "));productList.add(new Product(name, words, i));}for (Product product: productList){for (String word: product.words){if (wordsDict.contains(word)) {product.sameWordsNum++;}}}//排序实现,先比较product包含的关键词数量,再比较输入顺序Collections.sort(productList, (p1, p2) -> {if (p1.sameWordsNum != p2.sameWordsNum) {return p2.sameWordsNum - p1.sameWordsNum;}else{return p1.priority - p2.priority;}});for (Product product: productList){System.out.println(product.name);}}
}
class Product {String name;List<String> words;int sameWordsNum = 0;int priority;Product(String name, List<String> words, int priority) {this.name = name;this.words = words;this.priority = priority;}
}J