当前位置: 首页 > 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

相关文章:

  • 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 注入开放与修复
  • 针对异构数据的联邦学习
  • 白城网站建设公司/免费行情网站
  • 哈尔滨网页设计公司/西安百度网站排名优化
  • 制作网站的钱/哪里可以接广告
  • 泉州网站seo公司/google seo 优化教程
  • 东莞建设网站平台/百度热搜榜在哪里看
  • 漳州做网站多少钱/云优化