当前位置: 首页 > java >正文

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

http://www.xdnf.cn/news/12843.html

相关文章:

  • 第四讲 进程控制
  • Power Query动态追加查询(不同工作簿下)
  • 论文略读:Position: AI Evaluation Should Learn from How We Test Humans
  • PLC入门【2】PLC的接线
  • 系统模块与功能设计框架
  • 对F1分数的基本认识
  • 【AI论文】VS-Bench:评估多智能体环境中的视觉语言模型(VLM)在策略推理与决策制定方面的能力
  • 个人感悟-构建1000人商业帝国的战略计划
  • vulnyx lower2 writeup
  • 【优选算法】分治
  • Java线程池
  • nginx配置文件
  • leetcode238-除自身以外数组的乘积
  • 【JVM面试篇】高频八股汇总——Java内存区域
  • 华为OD机考 - 水仙花数 Ⅰ(2025B卷 100分)
  • 8. 二叉树(随想录)
  • 本地缓存在Java中的实现方式
  • “图像说话,文本有图”——用Python玩转跨模态数据关联分析
  • 【2025CVPR】模型融合新范式:PLeaS算法详解(基于排列与最小二乘的模型合并技术)
  • 飞云控盘指标-副图指标-买点一持仓操作技术图文解说
  • 初级程序员入门指南
  • 跟进一下目前最新的大数据技术
  • 设备驱动与文件系统:06 目录与文件
  • 骨盆-x光参数
  • python生成器
  • SWAN(Scade One) 语言原理介绍
  • Linux中《进程控制》详细介绍
  • RootSIFT的目标定位,opencvsharp。
  • DOM(文档对象模型)深度解析
  • 开源项目实战学习之YOLO11:12.6 ultralytics-models-tiny_encoder.py