• 猿辅导笔试


    单选题×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个)

    代码:

    1. import java.util.HashMap;
    2. import java.util.Scanner;
    3. public class Main{
    4. /*
    5. * 2
    6. 12 A tidy tiger tied a tie tighter to tidy her tiny tail
    7. 1 a
    8. 16 A big black bug bit a big black bear made the big black bear bleed blood
    9. 2 b?? b???
    10. *
    11. * */
    12. public static void main(String[] args) {
    13. Scanner sc = new Scanner(System.in);
    14. int M = sc.nextInt();
    15. sc.nextLine();
    16. for(int i=0;i
    17. String[] input = sc.nextLine().toLowerCase().split(" ");
    18. int N = Integer.parseInt(input[0]);
    19. String[] stop_word = sc.nextLine().split(" ");
    20. int K = Integer.parseInt(stop_word[0]);
    21. HashMap map = new HashMap<>();
    22. for(int j=1;j
    23. int t;
    24. for(t=1;t
    25. if(compare(input[j], stop_word[t])){
    26. break;
    27. }
    28. }
    29. if(t == stop_word.length){
    30. map.put(input[j], map.getOrDefault(input[j].toLowerCase(), 0) + 1);
    31. }
    32. }
    33. int res = 0;
    34. for(String s : map.keySet()){
    35. System.out.println(s);
    36. int tmp = map.get(s);
    37. res = res > tmp ? res : tmp;
    38. }
    39. System.out.println(res);
    40. }
    41. }
    42. public static boolean compare(String s, String t){
    43. if(s.length() != t.length()){
    44. return false;
    45. }
    46. s = s.toLowerCase();
    47. t = t.toLowerCase();
    48. for(int i=0;i
    49. if(s.charAt(i) == t.charAt(i) || t.charAt(i) == '?'){
    50. continue;
    51. }else{
    52. return false;
    53. }
    54. }
    55. return true;
    56. }
    57. }

    第二题:求包含所有质因数的最小子数组的长度

    第一行为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)

    这题是最小覆盖字串的变体,我是在考完才写出来,嘤嘤嘤

    1. import java.util.*;
    2. public class Test2 {
    3. /*
    4. * 2
    5. 20 8
    6. 1 2 3 2 6 5 2 1
    7. 17 10
    8. 1 4 5 7 10 8 7 17 2 8
    9. * */
    10. public static void main(String[] args) {
    11. Scanner sc = new Scanner(System.in);
    12. int M = Integer.parseInt(sc.nextLine());
    13. for(int i=0;i
    14. String[] input = sc.nextLine().split(" ");
    15. int K = Integer.parseInt(input[0]);
    16. int N = Integer.parseInt(input[1]);
    17. int[] A = new int[N];
    18. String[] s = sc.nextLine().split(" ");
    19. for(int j=0;j
    20. A[j] = Integer.parseInt(s[j]);
    21. }
    22. map = new HashMap<>();
    23. zhiyinzi(K, 2);
    24. print();
    25. int left = 0, right = 0;
    26. int valid = 0;
    27. int start = 0, end = N+1;
    28. Map window = new HashMap<>();
    29. while(right < N){
    30. int tmp = A[right];
    31. right++;
    32. if(map.containsKey(tmp)){
    33. window.put(tmp, window.getOrDefault(tmp, 0) + 1);
    34. if(window.get(tmp).equals(map.get(tmp))){
    35. valid++;
    36. }
    37. }
    38. while(valid == map.size()){
    39. if(right - left < end - start){
    40. start = left;
    41. end = right;
    42. }
    43. int left_delete = A[left];
    44. left++;
    45. if(map.containsKey(left_delete)){
    46. if(window.get(left_delete).equals(map.get(left_delete))){
    47. valid--;
    48. }
    49. window.put(left_delete, window.getOrDefault(left_delete, 0) - 1);
    50. }
    51. }
    52. }
    53. if(end == N + 1){
    54. System.out.println(0);
    55. }else{
    56. System.out.println(end - start);
    57. }
    58. }
    59. }
    60. public static void print(){
    61. for(int key : map.keySet()){
    62. System.out.println("key: " + key + " " + "value:" + map.get(key));
    63. }
    64. }
    65. public static boolean iszhishu(int m){
    66. for(int i = 2;i
    67. if(m % i == 0){
    68. return false;
    69. }
    70. }
    71. return true;
    72. }
    73. static HashMap map;
    74. public static void zhiyinzi(int n, int m){
    75. if(n < m){
    76. return;
    77. }else{
    78. if(iszhishu(m) && n % m == 0){
    79. map.put(m, map.getOrDefault(m, 0) + 1);
    80. zhiyinzi(n/m, m);
    81. }else{
    82. zhiyinzi(n, m+1);
    83. }
    84. }
    85. }
    86. }

     第三题没看,没时间了,一个半小时时间太赶了

  • 相关阅读:
    SAGA GIS使用教程
    区块链技术的应用场景和优势
    如何利用Web Components提高前端开发效率?
    问题越古老,解决方案存在的时间就越长
    什么测试自动化测试?
    pthread_mutex_unlock
    VSCode配置C/C++环境
    Spring JDK动态代理(附带实例)
    浅入浅出linux中断子系统
    MySQL·SQL优化
  • 原文地址:https://blog.csdn.net/qq_38235017/article/details/126550454