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

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.dtcms.com/a/238707.html

相关文章:

  • LeetCode 2894.分类求和并作差
  • 基于51单片机的花样流水灯
  • 6个月Python学习计划 Day 17 - 继承、多态与魔术方法
  • 程序问题实录
  • Python BeautifulSoup解析HTML获取图片URL并下载到本地
  • 【电路】阻抗匹配
  • 云原生架构赋能企业数字化转型:从理念到落地的系统性探索
  • springboot3.5整合Spring Security6.5默认密码没有打印输出控制台排查过程
  • BeanFactory 和 FactoryBean 有何区别与联系?
  • 在vs2022中的program.cs中已经没有app.useEndpoints
  • 分词算法总结:不同分词算法的优点和缺点
  • K8S认证|CKS题库+答案| 8. 沙箱运行容器 gVisor
  • 从入门到实战:AI学习路线全解析——避坑指南
  • AUTOSAR实战教程--开放式通用DoIP刷写工具OpenOTA开发计划
  • shell脚本 --案例实操
  • 【优选算法】模拟 问题算法
  • 【CSS-7】深入解析CSS伪类:从基础到高级应用
  • 73常用控件_QFormLayout的使用
  • SQL 注入开放与修复
  • 针对异构数据的联邦学习
  • Linux 基础IO(下)
  • D25异常处理
  • 【学习笔记】深入理解Java虚拟机学习笔记——第5章 调优案例分析与实战
  • NLP学习路线图(三十二): 模型压缩与优化
  • 从认识AI开始-----变分自编码器:从AE到VAE
  • LangChain工具集成实战:构建智能问答系统完整指南
  • springboot3.x对接AI智谱清言
  • 前端获取接口数据流程
  • 利用coze工作流制作一个自动生成PPT的智能体
  • ORACLE 修改端口号之后无法启动?