单选题×15, 程序题×3
单选有程序输出题、数据库的题、管道的题、http3.0、概率题等等
程序题第一题
第一行输入组数 第二行第一个输出字符串的数量N,后面的接N个字符串,使用空格隔开 第三行是需要删除的字符串,?表示任意一个字符 求出现最多的字符串的个数 输入: 2 12 A tidy tiger tied a tie tighter to tidy her tiny tail 1 a 16 A big black bug bit a big black bear made the big black bear bleed blood 2 b?? b???输出:
2(tidy有2个)
3(black有3个)
代码:
- import java.util.HashMap;
- import java.util.Scanner;
-
- public class Main{
-
- /*
- * 2
- 12 A tidy tiger tied a tie tighter to tidy her tiny tail
- 1 a
- 16 A big black bug bit a big black bear made the big black bear bleed blood
- 2 b?? b???
- *
- * */
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int M = sc.nextInt();
- sc.nextLine();
- for(int i=0;i
- String[] input = sc.nextLine().toLowerCase().split(" ");
- int N = Integer.parseInt(input[0]);
- String[] stop_word = sc.nextLine().split(" ");
- int K = Integer.parseInt(stop_word[0]);
- HashMap
map = new HashMap<>(); - for(int j=1;j
- int t;
- for(t=1;t
- if(compare(input[j], stop_word[t])){
- break;
- }
- }
- if(t == stop_word.length){
- map.put(input[j], map.getOrDefault(input[j].toLowerCase(), 0) + 1);
- }
- }
- int res = 0;
- for(String s : map.keySet()){
- System.out.println(s);
- int tmp = map.get(s);
- res = res > tmp ? res : tmp;
- }
- System.out.println(res);
- }
- }
-
- public static boolean compare(String s, String t){
- if(s.length() != t.length()){
- return false;
- }
- s = s.toLowerCase();
- t = t.toLowerCase();
- for(int i=0;i
- if(s.charAt(i) == t.charAt(i) || t.charAt(i) == '?'){
- continue;
- }else{
- return false;
- }
- }
- return true;
- }
- }
第二题:求包含所有质因数的最小子数组的长度
第一行为N
第二行第一个数为K,第二个数为N,代表数组的大小
第三行是数组
输入:
2
20 8
1 2 3 2 6 5 2 1
17 10
1 4 5 7 10 8 7 17 2 8
输出:4(20的所有质因数包括2,2,5, 其中最小的子数组包含2,6,5,2)
这题是最小覆盖字串的变体,我是在考完才写出来,嘤嘤嘤
- import java.util.*;
- public class Test2 {
-
- /*
- * 2
- 20 8
- 1 2 3 2 6 5 2 1
- 17 10
- 1 4 5 7 10 8 7 17 2 8
- * */
-
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int M = Integer.parseInt(sc.nextLine());
- for(int i=0;i
- String[] input = sc.nextLine().split(" ");
- int K = Integer.parseInt(input[0]);
- int N = Integer.parseInt(input[1]);
- int[] A = new int[N];
- String[] s = sc.nextLine().split(" ");
- for(int j=0;j
- A[j] = Integer.parseInt(s[j]);
- }
- map = new HashMap<>();
- zhiyinzi(K, 2);
- print();
- int left = 0, right = 0;
- int valid = 0;
- int start = 0, end = N+1;
- Map
window = new HashMap<>(); - while(right < N){
- int tmp = A[right];
- right++;
- if(map.containsKey(tmp)){
- window.put(tmp, window.getOrDefault(tmp, 0) + 1);
- if(window.get(tmp).equals(map.get(tmp))){
- valid++;
- }
- }
- while(valid == map.size()){
- if(right - left < end - start){
- start = left;
- end = right;
- }
- int left_delete = A[left];
- left++;
- if(map.containsKey(left_delete)){
- if(window.get(left_delete).equals(map.get(left_delete))){
- valid--;
- }
- window.put(left_delete, window.getOrDefault(left_delete, 0) - 1);
- }
- }
- }
- if(end == N + 1){
- System.out.println(0);
- }else{
- System.out.println(end - start);
- }
- }
- }
-
- public static void print(){
- for(int key : map.keySet()){
- System.out.println("key: " + key + " " + "value:" + map.get(key));
- }
- }
-
- public static boolean iszhishu(int m){
- for(int i = 2;i
- if(m % i == 0){
- return false;
- }
- }
- return true;
- }
-
- static HashMap
map; -
- public static void zhiyinzi(int n, int m){
- if(n < m){
- return;
- }else{
- if(iszhishu(m) && n % m == 0){
- map.put(m, map.getOrDefault(m, 0) + 1);
- zhiyinzi(n/m, m);
- }else{
- zhiyinzi(n, m+1);
- }
- }
- }
- }
第三题没看,没时间了,一个半小时时间太赶了
-
相关阅读:
SAGA GIS使用教程
区块链技术的应用场景和优势
如何利用Web Components提高前端开发效率?
问题越古老,解决方案存在的时间就越长
什么测试自动化测试?
pthread_mutex_unlock
VSCode配置C/C++环境
Spring JDK动态代理(附带实例)
浅入浅出linux中断子系统
MySQL·SQL优化
-
原文地址:https://blog.csdn.net/qq_38235017/article/details/126550454